pub struct CommandName { /* private fields */ }Expand description
A validated command name from the whitelist
This newtype ensures that only whitelisted commands can be constructed.
Implementations§
Source§impl CommandName
impl CommandName
Sourcepub fn new<S: AsRef<str>>(name: S) -> Result<Self>
pub fn new<S: AsRef<str>>(name: S) -> Result<Self>
Create a new CommandName from a string
§Validation Rules
- Command must be in the whitelist
- Command name cannot be empty
- Command name cannot contain whitespace
§Examples
use ggen_utils::safe_command::CommandName;
// Valid commands
assert!(CommandName::new("cargo").is_ok());
assert!(CommandName::new("git").is_ok());
// Invalid commands
assert!(CommandName::new("rm").is_err());
assert!(CommandName::new("").is_err());Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Convert into the inner String
Trait Implementations§
Source§impl Clone for CommandName
impl Clone for CommandName
Source§fn clone(&self) -> CommandName
fn clone(&self) -> CommandName
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CommandName
impl Debug for CommandName
Source§impl Display for CommandName
impl Display for CommandName
impl Eq for CommandName
Source§impl Hash for CommandName
impl Hash for CommandName
Source§impl PartialEq for CommandName
impl PartialEq for CommandName
impl StructuralPartialEq for CommandName
Source§impl TryFrom<&str> for CommandName
impl TryFrom<&str> for CommandName
Auto Trait Implementations§
impl Freeze for CommandName
impl RefUnwindSafe for CommandName
impl Send for CommandName
impl Sync for CommandName
impl Unpin for CommandName
impl UnsafeUnpin for CommandName
impl UnwindSafe for CommandName
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<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
Compare self to
key and return true if they are equal.