Struct git_config::parse::Comment
source · Expand description
A parsed comment containing the comment marker and comment.
Fields§
§tag: u8
The comment marker used. This is either a semicolon or octothorpe/hash.
text: Cow<'a, BStr>
The parsed comment.
Implementations§
source§impl Comment<'_>
impl Comment<'_>
sourcepub fn to_owned(&self) -> Comment<'static>
pub fn to_owned(&self) -> Comment<'static>
Turn this instance into a fully owned one with 'static
lifetime.
Examples found in repository?
src/parse/event.rs (line 54)
52 53 54 55 56 57 58 59 60 61 62 63 64
pub fn to_owned(&self) -> Event<'static> {
match self {
Event::Comment(e) => Event::Comment(e.to_owned()),
Event::SectionHeader(e) => Event::SectionHeader(e.to_owned()),
Event::SectionKey(e) => Event::SectionKey(e.to_owned()),
Event::Value(e) => Event::Value(Cow::Owned(e.clone().into_owned())),
Event::ValueNotDone(e) => Event::ValueNotDone(Cow::Owned(e.clone().into_owned())),
Event::ValueDone(e) => Event::ValueDone(Cow::Owned(e.clone().into_owned())),
Event::Newline(e) => Event::Newline(Cow::Owned(e.clone().into_owned())),
Event::Whitespace(e) => Event::Whitespace(Cow::Owned(e.clone().into_owned())),
Event::KeyValueSeparator => Event::KeyValueSeparator,
}
}
sourcepub fn to_bstring(&self) -> BString
pub fn to_bstring(&self) -> BString
Serialize this type into a BString
for convenience.
Note that to_string()
can also be used, but might not be lossless.
Examples found in repository?
src/parse/comment.rs (line 36)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.to_bstring(), f)
}
}
impl From<Comment<'_>> for BString {
fn from(c: Comment<'_>) -> Self {
c.into()
}
}
impl From<&Comment<'_>> for BString {
fn from(c: &Comment<'_>) -> Self {
c.to_bstring()
}
sourcepub fn write_to(&self, out: impl Write) -> Result<()>
pub fn write_to(&self, out: impl Write) -> Result<()>
Stream ourselves to the given out
, in order to reproduce this comment losslessly.
Examples found in repository?
More examples
src/parse/event.rs (line 46)
36 37 38 39 40 41 42 43 44 45 46 47 48
pub fn write_to(&self, mut out: impl std::io::Write) -> std::io::Result<()> {
match self {
Self::ValueNotDone(e) => {
out.write_all(e.as_ref())?;
out.write_all(b"\\")
}
Self::Whitespace(e) | Self::Newline(e) | Self::Value(e) | Self::ValueDone(e) => out.write_all(e.as_ref()),
Self::KeyValueSeparator => out.write_all(b"="),
Self::SectionKey(k) => out.write_all(k.0.as_ref()),
Self::SectionHeader(h) => h.write_to(&mut out),
Self::Comment(c) => c.write_to(&mut out),
}
}
Trait Implementations§
source§impl<'a> Ord for Comment<'a>
impl<'a> Ord for Comment<'a>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<'a> PartialEq<Comment<'a>> for Comment<'a>
impl<'a> PartialEq<Comment<'a>> for Comment<'a>
source§impl<'a> PartialOrd<Comment<'a>> for Comment<'a>
impl<'a> PartialOrd<Comment<'a>> for Comment<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more