mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 22:46:02 +02:00
add in a raw flag in the command to json (#555)
* add in the method to_string_raw * add in a raw flag to json * add in a test
This commit is contained in:
@@ -2,7 +2,7 @@ pub use self::de::{
|
||||
from_iter, from_reader, from_slice, from_str, Deserializer, StreamDeserializer,
|
||||
};
|
||||
pub use self::error::{Error, ErrorCode, Result};
|
||||
pub use self::ser::{to_string, to_vec, to_writer, Serializer};
|
||||
pub use self::ser::{to_string, to_string_raw, to_vec, to_writer, Serializer};
|
||||
pub use self::value::{from_value, to_value, Map, Value};
|
||||
|
||||
pub mod builder;
|
||||
|
@@ -1023,3 +1023,16 @@ where
|
||||
let string = String::from_utf8(vec)?;
|
||||
Ok(string)
|
||||
}
|
||||
|
||||
/// Encode the specified struct into a Hjson `String` buffer.
|
||||
/// And remove all whitespace
|
||||
#[inline]
|
||||
pub fn to_string_raw<T>(value: &T) -> Result<String>
|
||||
where
|
||||
T: ser::Serialize,
|
||||
{
|
||||
let vec = to_vec(value)?;
|
||||
let mut string = String::from_utf8(vec)?;
|
||||
string.retain(|c| !c.is_whitespace());
|
||||
Ok(string)
|
||||
}
|
||||
|
Reference in New Issue
Block a user