Struct git_config::file::Metadata
source · pub struct Metadata {
pub path: Option<PathBuf>,
pub source: Source,
pub level: u8,
pub trust: Trust,
}
Expand description
Additional information about a section.
Fields§
§path: Option<PathBuf>
The file path of the source, if known.
source: Source
Where the section is coming from.
level: u8
The levels of indirection of the file, with 0 being a section
that was directly loaded, and 1 being an include.path
of a
level 0 file.
trust: Trust
The trust-level for the section this meta-data is associated with.
Implementations§
source§impl Metadata
impl Metadata
Instantiation
sourcepub fn api() -> Self
pub fn api() -> Self
Return metadata indicating the source of a File
is from an API user.
Examples found in repository?
More examples
src/file/impls.rs (line 18)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
fn from_str(s: &str) -> Result<Self, Self::Err> {
parse::Events::from_bytes_owned(s.as_bytes(), None)
.map(|events| File::from_parse_events_no_includes(events, Metadata::api()))
}
}
impl<'a> TryFrom<&'a str> for File<'a> {
type Error = parse::Error;
/// Convenience constructor. Attempts to parse the provided string into a
/// [`File`]. See [`Events::from_str()`][crate::parse::Events::from_str()] for more information.
fn try_from(s: &'a str) -> Result<File<'a>, Self::Error> {
parse::Events::from_str(s).map(|events| Self::from_parse_events_no_includes(events, Metadata::api()))
}
}
impl<'a> TryFrom<&'a BStr> for File<'a> {
type Error = parse::Error;
/// Convenience constructor. Attempts to parse the provided byte string into
/// a [`File`]. See [`Events::from_bytes()`][parse::Events::from_bytes()] for more information.
fn try_from(value: &'a BStr) -> Result<File<'a>, Self::Error> {
parse::Events::from_bytes(value, None)
.map(|events| Self::from_parse_events_no_includes(events, Metadata::api()))
}
sourcepub fn try_from_path(path: impl Into<PathBuf>, source: Source) -> Result<Self>
pub fn try_from_path(path: impl Into<PathBuf>, source: Source) -> Result<Self>
Return metadata as derived from the given path
at source
, which will also be used to derive the trust level
by checking its ownership.
sourcepub fn with(self, trust: Trust) -> Self
pub fn with(self, trust: Trust) -> Self
Set the trust level of this instance to the given trust
and return it.
Useful in conjunction with Metadata::from(source)
.
Examples found in repository?
src/file/init/from_paths.rs (line 32)
23 24 25 26 27 28 29 30 31 32 33 34 35
pub fn from_path_no_includes(path: impl Into<std::path::PathBuf>, source: crate::Source) -> Result<Self, Error> {
let path = path.into();
let trust = git_sec::Trust::from_path_ownership(&path)?;
let mut buf = Vec::new();
std::io::copy(&mut std::fs::File::open(&path)?, &mut buf)?;
Ok(File::from_bytes_owned(
&mut buf,
Metadata::from(source).at(path).with(trust),
Default::default(),
)?)
}
sourcepub fn at(self, path: impl Into<PathBuf>) -> Self
pub fn at(self, path: impl Into<PathBuf>) -> Self
Set the metadata to be located at the given path
.
Examples found in repository?
src/file/init/from_paths.rs (line 32)
23 24 25 26 27 28 29 30 31 32 33 34 35
pub fn from_path_no_includes(path: impl Into<std::path::PathBuf>, source: crate::Source) -> Result<Self, Error> {
let path = path.into();
let trust = git_sec::Trust::from_path_ownership(&path)?;
let mut buf = Vec::new();
std::io::copy(&mut std::fs::File::open(&path)?, &mut buf)?;
Ok(File::from_bytes_owned(
&mut buf,
Metadata::from(source).at(path).with(trust),
Default::default(),
)?)
}
Trait Implementations§
source§impl Ord for Metadata
impl Ord for Metadata
source§impl PartialEq<Metadata> for Metadata
impl PartialEq<Metadata> for Metadata
source§impl PartialOrd<Metadata> for Metadata
impl PartialOrd<Metadata> for Metadata
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