pub struct RegexVersionFile { /* private fields */ }Expand description
A version file engine driven by a user-supplied regex.
The regex must contain at least one capture group. The first capture group is treated as the version string for both reading and writing.
Implementations§
Source§impl RegexVersionFile
impl RegexVersionFile
Sourcepub fn new(custom: &CustomVersionFile) -> Result<Self, VersionFileError>
pub fn new(custom: &CustomVersionFile) -> Result<Self, VersionFileError>
Create a new engine from a CustomVersionFile config entry.
§Errors
Returns VersionFileError::InvalidRegex if the pattern fails to
compile or contains no capture groups.
Sourcepub fn detect(&self, content: &str) -> bool
pub fn detect(&self, content: &str) -> bool
Check if content contains a match for the regex pattern.
Sourcepub fn read_version(&self, content: &str) -> Option<String>
pub fn read_version(&self, content: &str) -> Option<String>
Extract the version string from the first capture group.
Sourcepub fn write_version(
&self,
content: &str,
new_version: &str,
) -> Result<String, VersionFileError>
pub fn write_version( &self, content: &str, new_version: &str, ) -> Result<String, VersionFileError>
Return updated content with the first capture group replaced by
new_version, preserving all surrounding text.
§Errors
Returns VersionFileError::NoVersionField if the regex does not
match content.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RegexVersionFile
impl RefUnwindSafe for RegexVersionFile
impl Send for RegexVersionFile
impl Sync for RegexVersionFile
impl Unpin for RegexVersionFile
impl UnsafeUnpin for RegexVersionFile
impl UnwindSafe for RegexVersionFile
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