pub struct TypeAnnotation {
pub name: String,
pub major_version: u32,
pub minor_version: u32,
}Expand description
A type annotation from CollecTor descriptor archives.
CollecTor archives include a type annotation on the first line of each
descriptor file in the format @type <name> <major>.<minor>. This struct
represents that parsed annotation.
§Format
@type server-descriptor 1.0
@type network-status-consensus-3 1.0
@type microdescriptor 1.0§Example
use stem_rs::descriptor::TypeAnnotation;
let annotation = TypeAnnotation::parse("@type server-descriptor 1.0").unwrap();
assert_eq!(annotation.name, "server-descriptor");
assert_eq!(annotation.major_version, 1);
assert_eq!(annotation.minor_version, 0);
// Convert back to string
assert_eq!(annotation.to_string(), "@type server-descriptor 1.0");§See Also
DescriptorType- Enum of known descriptor typesstrip_type_annotation- Extract annotation from content
Fields§
§name: StringThe descriptor type name (e.g., “server-descriptor”, “microdescriptor”).
major_version: u32The major version number.
minor_version: u32The minor version number.
Implementations§
Source§impl TypeAnnotation
impl TypeAnnotation
Sourcepub fn new(
name: impl Into<String>,
major_version: u32,
minor_version: u32,
) -> Self
pub fn new( name: impl Into<String>, major_version: u32, minor_version: u32, ) -> Self
Creates a new type annotation with the given name and version.
§Arguments
name- The descriptor type namemajor_version- The major version numberminor_version- The minor version number
§Example
use stem_rs::descriptor::TypeAnnotation;
let annotation = TypeAnnotation::new("server-descriptor", 1, 0);
assert_eq!(annotation.to_string(), "@type server-descriptor 1.0");Sourcepub fn parse(line: &str) -> Option<Self>
pub fn parse(line: &str) -> Option<Self>
Parses a type annotation from a line of text.
Returns None if the line is not a valid type annotation.
§Arguments
line- The line to parse
§Example
use stem_rs::descriptor::TypeAnnotation;
// Valid annotation
let annotation = TypeAnnotation::parse("@type extra-info 1.0").unwrap();
assert_eq!(annotation.name, "extra-info");
// Invalid - not an annotation
assert!(TypeAnnotation::parse("router test 127.0.0.1").is_none());
// Invalid - missing version
assert!(TypeAnnotation::parse("@type server-descriptor").is_none());Trait Implementations§
Source§impl Clone for TypeAnnotation
impl Clone for TypeAnnotation
Source§fn clone(&self) -> TypeAnnotation
fn clone(&self) -> TypeAnnotation
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TypeAnnotation
impl Debug for TypeAnnotation
Source§impl Display for TypeAnnotation
impl Display for TypeAnnotation
Source§impl PartialEq for TypeAnnotation
impl PartialEq for TypeAnnotation
impl Eq for TypeAnnotation
impl StructuralPartialEq for TypeAnnotation
Auto Trait Implementations§
impl Freeze for TypeAnnotation
impl RefUnwindSafe for TypeAnnotation
impl Send for TypeAnnotation
impl Sync for TypeAnnotation
impl Unpin for TypeAnnotation
impl UnwindSafe for TypeAnnotation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more