pub struct Label {
pub ref_type: String,
pub ref_label: String,
}Expand description
A label, as written in \label{type:label}: the label type before the
first colon, and the label proper after it.
A label is the text an author writes as \label{type:label} after a
construct, which the construct reads as a field and attaches to its
reference point (see reference points, labels and
anchors).
The reference point carries its labels in RefPoint::labels, and a
reference site gives the label it points at in RefSite::target. The
label type is part of the label and does not depend on the reference
kind of the point, so one point may carry labels of several
types, among those the point accepts, and each label is
looked up as a whole.
Fields§
§ref_type: StringThe label type (sec in sec:intro).
ref_label: StringThe label proper (intro in sec:intro).
Implementations§
Source§impl Label
impl Label
Sourcepub fn new(ref_type: impl Into<String>, ref_label: impl Into<String>) -> Label
pub fn new(ref_type: impl Into<String>, ref_label: impl Into<String>) -> Label
A label made of the label type ref_type and the label proper
ref_label, taken as given (no trimming, no check).
Sourcepub fn parse(text: &str) -> Option<Label>
pub fn parse(text: &str) -> Option<Label>
Reads a label from its written form type:label: the text before the
first colon is the label type, everything after it (further colons
included) is the label proper. In each part, every run of whitespace
(the space, the tab, the carriage return and the line feed: the
whitespace of FLM text) is made one space
and the whitespace at both ends is removed, as in a citation key
(spelling_identity);
every other character counts as written, quotes, dashes and the no-break
space U+00A0 included. A label written with a doubled space, or broken
over two lines, is therefore the label written with one space.
The standard features read every label a document writes with this
function (a \label, the target of a \ref, a \hyperref or an
\eqref, a proof’s back-reference), so that a label and a reference to
it agree.
Returns None when the text holds no colon, or when either part is
empty after the whitespace is removed. A caller that reads a label from
a document reports that case with a diagnostic at the label’s span (see
MalformedLabel).
§Examples
use flm_core::model::aspects::Label;
let label = Label::parse("sec:intro").unwrap();
assert_eq!(label.ref_type, "sec");
assert_eq!(label.ref_label, "intro");
assert_eq!(label.to_string(), "sec:intro");
assert_eq!(Label::parse(" sec : a \n b "), Some(Label::new("sec", "a b")));
assert!(Label::parse("no-colon-here").is_none());Trait Implementations§
impl Eq for Label
Source§impl Ord for Label
impl Ord for Label
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Label
impl PartialOrd for Label
impl StructuralPartialEq for Label
Auto Trait Implementations§
impl Forget for Label
impl Freeze for Label
impl Move for Label
impl RefUnwindSafe for Label
impl Send for Label
impl Sync for Label
impl Unpin for Label
impl UnsafeUnpin for Label
impl UnwindSafe for Label
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more