pub struct FilesystemSource { /* private fields */ }
Expand description
A Source that loads packages from the filesystem. This is a good source to use for development, or if you don’t care about packaging your data files into an archive.
Implementations§
Source§impl FilesystemSource
impl FilesystemSource
Sourcepub fn new(directory: &str, trust: TrustLevel) -> FilesystemSource
pub fn new(directory: &str, trust: TrustLevel) -> FilesystemSource
Creates a new FilesystemSource using the given directory to look for packages in
Examples found in repository?
examples/basic.rs (line 44)
40fn main()
41{
42 println!("Listing items in mypackage/text:");
43
44 let mut source = FilesystemSource::new("examples", TrustLevel::TrustedSource);
45 let iter = source.iter_entries("mypackage", "text");
46
47 for entry in iter
48 {
49 match entry
50 {
51 Ok(pathname) => println!("{}", pathname),
52 Err(error) => println!("Error: {}", error)
53 }
54 }
55
56 println!("Loading files from mypackage/text...");
57
58 let source_manager = Rc::new(RefCell::new(SourceManager::new()));
59 source_manager.borrow_mut().add_source(Box::new(source));
60
61 let mut store = DataStore::<TextData>::new(source_manager);
62
63 store.load_package("mypackage").expect("Failed to load package.");
64
65 for name in &["emoji.txt", "missingfile.txt", "loremipsum.txt"]
66 {
67 match store.get_id("mypackage", name)
68 {
69 Ok(id) =>
70 {
71 println!("Contents of {}:", name);
72 match store.get(id)
73 {
74 Some(data) => println!("{}", data.text),
75 None => println!("(not found)"),
76 }
77 }
78 Err(error) =>
79 {
80 println!("Error for {}:\n{}", name, error);
81 }
82 }
83
84 println!("");
85 }
86}
Trait Implementations§
Source§impl Source for FilesystemSource
impl Source for FilesystemSource
Source§fn get_uri(&self) -> &str
fn get_uri(&self) -> &str
The path that this Source originates from. Only used for debug purposes.
Source§fn has_package(&self, package_name: &str) -> bool
fn has_package(&self, package_name: &str) -> bool
Returns true if the Source has a package of the given name, otherwise returns false
Source§fn list_packages(&mut self) -> Vec<String>
fn list_packages(&mut self) -> Vec<String>
Returns a list of all packages available in this Source. Do not call this repeatedly!
Source§fn read_file<'a>(
&'a mut self,
package_name: &str,
pathname: &str,
) -> Result<Box<dyn ReadSeek + 'a>, PackageError>
fn read_file<'a>( &'a mut self, package_name: &str, pathname: &str, ) -> Result<Box<dyn ReadSeek + 'a>, PackageError>
Source§fn write_file<'a>(
&'a mut self,
package_name: &str,
pathname: &str,
) -> Result<Box<dyn Write + 'a>, PackageError>
fn write_file<'a>( &'a mut self, package_name: &str, pathname: &str, ) -> Result<Box<dyn Write + 'a>, PackageError>
Returns a Write for the file at the given pathname.
Source§fn iter_entries<'a>(
&'a mut self,
package_name: &str,
type_folder: &str,
) -> Box<dyn Iterator<Item = Result<String, PackageError>> + 'a>
fn iter_entries<'a>( &'a mut self, package_name: &str, type_folder: &str, ) -> Box<dyn Iterator<Item = Result<String, PackageError>> + 'a>
Returns an iterator through the items in a given package, if the Source has said package
Source§fn trust_level(&self, _package_name: &str) -> TrustLevel
fn trust_level(&self, _package_name: &str) -> TrustLevel
Returns the source’s trust level for the given package. Trusted sources are able to load
resource types marked as requiring trust.
Auto Trait Implementations§
impl Freeze for FilesystemSource
impl RefUnwindSafe for FilesystemSource
impl Send for FilesystemSource
impl Sync for FilesystemSource
impl Unpin for FilesystemSource
impl UnwindSafe for FilesystemSource
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.