--- original +++ modified @@ -259,6 +259,20 @@ pub fn root_scroll_id(&self) -> webrender_api::ExternalScrollId { ExternalScrollId(0, self.into()) } + + pub fn from_string(str: &str) -> Option { + let re = Regex::new(r"^Pipeline\((\d+),(\d+)\)$").ok()?; + let caps = re.captures(str)?; + let namespace_id = caps.get(1)?.as_str().parse::().ok()?; + let index = caps.get(2)?.as_str().parse::().ok()?; + + let result = PipelineId { + namespace_id: PipelineNamespaceId(namespace_id), + index: Index::new(index).ok()?, + }; + assert_eq!(result.to_string(), str.to_string()); + Some(result) + } } impl From for PipelineId { @@ -345,6 +359,24 @@ pub fn mock_for_testing(browsing_context_id: BrowsingContextId) -> WebViewId { WebViewId(TEST_PAINTER_ID, browsing_context_id) } + + /// Parse a WebViewId from its string representation. + /// Format: "PainterId: {id}, TopLevel({namespace},{index})" + pub fn from_string(str: &str) -> Option { + let re = Regex::new(r"^PainterId: (\d+), TopLevelBrowsingContext\((\d+),(\d+)\)$").ok()?; + let caps = re.captures(str)?; + let painter_id = caps.get(1)?.as_str().parse::().ok()?; + let namespace_id = caps.get(2)?.as_str().parse::().ok()?; + let index = caps.get(3)?.as_str().parse::().ok()?; + + let browsing_context_id = BrowsingContextId { + namespace_id: PipelineNamespaceId(namespace_id), + index: Index::new(index).ok()?, + }; + let result = WebViewId(PainterId(painter_id), browsing_context_id); + assert_eq!(result.to_string(), str.to_string()); + Some(result) + } } impl From for BrowsingContextId {