strip_type_annotation

Function strip_type_annotation 

Source
pub fn strip_type_annotation(content: &str) -> (Option<TypeAnnotation>, &str)
Expand description

Strips a type annotation from the beginning of descriptor content.

If the first line is a valid @type annotation, it is parsed and removed from the content. Otherwise, the content is returned unchanged.

§Arguments

  • content - The descriptor content

§Returns

A tuple of:

  • Option<TypeAnnotation> - The parsed annotation if present
  • &str - The remaining content after the annotation

§Example

use stem_rs::descriptor::strip_type_annotation;

let content = "@type server-descriptor 1.0\nrouter example 127.0.0.1";
let (annotation, rest) = strip_type_annotation(content);

assert!(annotation.is_some());
assert_eq!(annotation.unwrap().name, "server-descriptor");
assert_eq!(rest, "router example 127.0.0.1");

// Without annotation
let content = "router example 127.0.0.1";
let (annotation, rest) = strip_type_annotation(content);
assert!(annotation.is_none());
assert_eq!(rest, content);