pub struct OrdPathBuf<E: Encoding = DefaultEncoding, const N: usize = USIZE_BYTES> { /* private fields */ }Expand description
A data type representing an ORDPATH is stored as a continuous sequence of bytes.
Implementations§
Source§impl<E: Encoding, const N: usize> OrdPathBuf<E, N>
impl<E: Encoding, const N: usize> OrdPathBuf<E, N>
Sourcepub fn from_ordinals(s: &[i64], enc: E) -> Self
pub fn from_ordinals(s: &[i64], enc: E) -> Self
Encodes a slice s to return a new OrdPath with the specified encoding.
§Panics
This function might panic if the given slice contains ordinals that are out of the range the provided encoding supports, or the resulting ORDPATH exceeds the maximum supported length.
See also [OrdPath::try_from_ordinals] which will return an Error rather than panicking.
Sourcepub fn from_str(s: &str, enc: E) -> Self
pub fn from_str(s: &str, enc: E) -> Self
Parses a string s to return a new OrdPath with the specified encoding.
§Panics
This function might panic if the given string contains any value other than numbers separated by dots, or it contains numbers that are out of the range the provided encoding supports, or the resulting ORDPATH exceeds the maximum supported length.
See also [OrdPath::try_from_str] which will return an Error rather than panicking.
Sourcepub fn from_bytes(s: &[u8], enc: E) -> Self
pub fn from_bytes(s: &[u8], enc: E) -> Self
Creates an OrdPath from a byte slice s.
§Panics
This function might panic if the given slice is not a valid ORDPATH, it cannot be read by the provided encoding, or the given slice exceeds the maximum supported length.
See also [OrdPath::try_from_bytes] which will return an Error rather than panicking.
Sourcepub fn try_from_ordinals(s: &[i64], enc: E) -> Result<Self, Error>
pub fn try_from_ordinals(s: &[i64], enc: E) -> Result<Self, Error>
Tries to encode a slice of ordinals s and create a new OrdPath.
Sourcepub fn try_from_str(s: &str, enc: E) -> Result<Self, Error>
pub fn try_from_str(s: &str, enc: E) -> Result<Self, Error>
Tries to parse a string s and create a new OrdPath.
Sourcepub fn try_from_bytes(s: &[u8], enc: E) -> Result<Self, Error>
pub fn try_from_bytes(s: &[u8], enc: E) -> Result<Self, Error>
Tries to create an OrdPath from a byte slice ’s`.
Methods from Deref<Target = OrdPath<E, N>>§
Sourcepub fn ordinals(&self) -> Ordinals<&Bytes, &E> ⓘ
pub fn ordinals(&self) -> Ordinals<&Bytes, &E> ⓘ
Produces an iterator over the ordinals of an OrdPath.
Sourcepub fn ancestors(&self) -> Ancestors<'_, E, N> ⓘ
pub fn ancestors(&self) -> Ancestors<'_, E, N> ⓘ
Produces an iterator over OrdPath ancestors.
The iterator will yield the OrdPath that is returned if the [parent] method is used one
or more times. If the [parent] method returns None, the iterator will do likewise.
§Examples
let path = <OrdPathBuf>::from_ordinals(&[1, 2, 3], DefaultEncoding);
let mut ancestors = path.ancestors();
assert_eq!(ancestors.next().map(|p| p.to_string()), Some("1.2".to_owned()));
assert_eq!(ancestors.next().map(|p| p.to_string()), Some("1".to_owned()));
assert_eq!(ancestors.next().map(|p| p.to_string()), Some("".to_owned()));
assert_eq!(ancestors.next(), None);Sourcepub fn parent(&self) -> Option<&OrdPath<E, N>>
pub fn parent(&self) -> Option<&OrdPath<E, N>>
Returns the OrdPath without its final element, if there is one.
Sourcepub fn is_ancestor_of(&self, other: &Self) -> boolwhere
E: PartialEq,
pub fn is_ancestor_of(&self, other: &Self) -> boolwhere
E: PartialEq,
Returns true if self is an ancestor of other.
§Examples
let a = <OrdPathBuf>::from_ordinals(&[1, 2], DefaultEncoding);
let d = <OrdPathBuf>::from_ordinals(&[1, 2, 3], DefaultEncoding);
assert!(a.is_ancestor_of(&d));See also OrdPath::is_descendant_of.
Sourcepub fn is_descendant_of(&self, other: &Self) -> boolwhere
E: PartialEq,
pub fn is_descendant_of(&self, other: &Self) -> boolwhere
E: PartialEq,
Returns true if self is an descendant of other.
§Examples
let a = <OrdPathBuf>::from_ordinals(&[1, 2], DefaultEncoding);
let d = <OrdPathBuf>::from_ordinals(&[1, 2, 3], DefaultEncoding);
assert!(d.is_descendant_of(&a));See also OrdPath::is_ancestor_of.