Add bytes collect, bytes remove, bytes build cmd (#6008)

* add bytes collect

* index_of support searching from end

* add bytes remove

* make bytes replace work better for empty pattern

* add bytes build

* remove comment

* tweak words

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
WindSoilder
2022-07-11 19:26:00 +08:00
committed by GitHub
parent 920e0acb85
commit 9e3c64aa84
8 changed files with 492 additions and 25 deletions

View File

@ -404,6 +404,27 @@ impl FromValue for Vec<u8> {
}
}
impl FromValue for Spanned<Vec<u8>> {
fn from_value(v: &Value) -> Result<Self, ShellError> {
match v {
Value::Binary { val, span } => Ok(Spanned {
item: val.clone(),
span: *span,
}),
Value::String { val, span } => Ok(Spanned {
item: val.bytes().collect(),
span: *span,
}),
v => Err(ShellError::CantConvert(
"binary data".into(),
v.get_type().to_string(),
v.span()?,
None,
)),
}
}
}
impl FromValue for Spanned<PathBuf> {
fn from_value(v: &Value) -> Result<Self, ShellError> {
match v {