From 0e6510c84fa1429f8d57318427bbb7b176f98938 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 18 May 2018 11:51:12 +0800 Subject: [PATCH] Fix &'static str -> &str. --- Cargo.toml | 2 +- src/lib.rs | 3 +++ src/sfs.rs | 6 +++--- src/structs.rs | 8 ++++---- src/vfs.rs | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa77d7b..c64817d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.1" authors = ["WangRunji "] [lib] -crate-type = ["staticlib"] +#crate-type = ["staticlib"] [profile.dev] panic = 'abort' # prevent `_Unwind_Resume` link error diff --git a/src/lib.rs b/src/lib.rs index 6ca8455..ffef679 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,9 @@ pub mod c_interface; #[cfg(test)] mod tests; +pub use sfs::*; +pub use vfs::*; + #[cfg(feature = "ucore")] #[global_allocator] pub static UCORE_ALLOCATOR: c_interface::UcoreAllocator = c_interface::UcoreAllocator{}; \ No newline at end of file diff --git a/src/sfs.rs b/src/sfs.rs index ae02b9c..cbf7c89 100644 --- a/src/sfs.rs +++ b/src/sfs.rs @@ -96,7 +96,7 @@ impl INode { } } /// Only for Dir - fn get_file_inode_id(&self, name: &'static str) -> Option { + fn get_file_inode_id(&self, name: &str) -> Option { (0..self.disk_inode.blocks) .map(|i| { use vfs::INode; @@ -249,7 +249,7 @@ impl vfs::INode for INode { assert_eq!(self.disk_inode.type_, FileType::File, "resize is only available on file"); self._resize(len) } - fn create(&mut self, name: &'static str, type_: vfs::FileType) -> vfs::Result> { + fn create(&mut self, name: &str, type_: vfs::FileType) -> vfs::Result> { let fs = self.fs.upgrade().unwrap(); let info = self.info().unwrap(); assert_eq!(info.type_, vfs::FileType::Dir); @@ -273,7 +273,7 @@ impl vfs::INode for INode { Ok(inode) } - fn lookup(&self, path: &'static str) -> vfs::Result> { + fn lookup(&self, path: &str) -> vfs::Result> { let fs = self.fs.upgrade().unwrap(); let info = self.info().unwrap(); assert_eq!(info.type_, vfs::FileType::Dir); diff --git a/src/structs.rs b/src/structs.rs index 7a08064..3bd7caf 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -82,15 +82,15 @@ impl Debug for Str32 { write!(f, "{}", self.as_ref()) } } -impl From<&'static str> for Str256 { - fn from(s: &'static str) -> Self { +impl<'a> From<&'a str> for Str256 { + fn from(s: &'a str) -> Self { let mut ret = [0u8; 256]; ret[0..s.len()].copy_from_slice(s.as_ref()); Str256(ret) } } -impl From<&'static str> for Str32 { - fn from(s: &'static str) -> Self { +impl<'a> From<&'a str> for Str32 { + fn from(s: &'a str) -> Self { let mut ret = [0u8; 32]; ret[0..s.len()].copy_from_slice(s.as_ref()); Str32(ret) diff --git a/src/vfs.rs b/src/vfs.rs index be0c2a6..fa85633 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -22,8 +22,8 @@ pub trait INode: Debug { // fn name_file(&mut self) -> Result<()>; // fn reclaim(&mut self) -> Result<()>; fn resize(&mut self, len: usize) -> Result<()>; - fn create(&mut self, name: &'static str, type_: FileType) -> Result; - fn lookup(&self, path: &'static str) -> Result; + fn create(&mut self, name: &str, type_: FileType) -> Result; + fn lookup(&self, path: &str) -> Result; fn list(&self) -> Result>; // fn io_ctrl(&mut self, op: u32, data: &[u8]) -> Result<()>; fn fs(&self) -> Weak;