pub struct File {
pub name: String,
pub content: String,
pub encoding: String,
}Expand description
A file that contains source code to be executed.
Fields§
§name: String§content: StringRequired The content of the file.
encoding: StringThe encoding of the file. Defaults to “utf8”.
Implementations§
Source§impl File
impl File
Sourcepub fn new(name: &str, content: &str, encoding: &str) -> Self
pub fn new(name: &str, content: &str, encoding: &str) -> Self
Creates a new File.
§Arguments
name- The name to use.content- The content to use.encoding- The encoding to use. Must be one of “utf8”, “hex”, or “base64”.
§Returns
File- The new File.
§Example
let file = piston_rs::File::new(
"script.sh",
"ZWNobyBIZWxsbywgV29ybGQh",
"base64",
);
assert!(file.content.contains("ZWNobyBIZWxsbywgV29ybGQh"));
assert_eq!(file.name, "script.sh".to_string());
assert_eq!(file.encoding, "base64".to_string());Sourcepub fn load_from(path: &str) -> Result<Self, LoadError>
pub fn load_from(path: &str) -> Result<Self, LoadError>
Creates a new File from an existing file on disk.
§Arguments
path- The path to the file.
§Returns
File- The new File.
§Example
let file = piston_rs::File::load_from("src/lib.rs").unwrap();
assert!(file.content.contains("pub fn load_from"));
assert_eq!(file.name, "lib.rs".to_string());
assert_eq!(file.encoding, "utf8".to_string());Sourcepub fn set_content(self, content: &str) -> Self
pub fn set_content(self, content: &str) -> Self
Sourcepub fn load_content_from(self, path: &str) -> Result<Self, LoadError>
pub fn load_content_from(self, path: &str) -> Result<Self, LoadError>
Sets the content of the file to the contents of an existing file on disk.
§Arguments
path- The path to the file.
§Returns
Self- For chained method calls.
§Example
let file = piston_rs::File::default()
.load_content_from("src/lib.rs");
assert!(file.is_ok());
assert!(file.unwrap().content.contains("pub fn load_content_from"));Sourcepub fn set_encoding(self, encoding: &str) -> Self
pub fn set_encoding(self, encoding: &str) -> Self
Trait Implementations§
Source§impl<'de> Deserialize<'de> for File
impl<'de> Deserialize<'de> for File
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for File
impl StructuralPartialEq for File
Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnwindSafe for File
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.