Repository navigation
Fix implicit 'static bound on EntityResolve dyn trait type alias. - #149
Conversation
|
@PeterlitsZo Could you please try this branch over at Kimahriman/hdfs-native#260? The following diff worked for me: diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 1f0497e..c6d8a18 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -37,7 +37,7 @@ prost = "0.14"
prost-types = "0.14"
rand = "0.9"
regex = "1"
-roxmltree = { git = "https://github.com/RazrFalcon/roxmltree.git", rev = "634f4d0" } # TODO: Update it when new version is released.
+roxmltree = { git = "https://github.com/RazrFalcon/roxmltree.git", branch = "fix-implicit-static" } # TODO: Update it when new version is released.
socket2 = "0.6"
thiserror = { workspace = true }
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "net", "io-util", "macros", "sync", "time"] }
diff --git a/rust/src/common/config.rs b/rust/src/common/config.rs
index a16ba36..5b34d9d 100644
--- a/rust/src/common/config.rs
+++ b/rust/src/common/config.rs
@@ -207,10 +207,10 @@ impl Configuration {
fn read_from_file(path: &Path) -> Result<Vec<(String, String)>> {
let content = fs::read_to_string(path)?;
let mut resolver = EntityResolver::new(path)?;
- let mut entity_resolver = move |_: Option<&str>, uri: &str| resolver.resolve(uri);
+ let entity_resolver = |_: Option<&str>, uri: &str| resolver.resolve(uri);
let opts = roxmltree::ParsingOptions {
allow_dtd: true,
- entity_resolver: Some(&mut entity_resolver),
+ entity_resolver: Some(&entity_resolver),
..Default::default()
};
let tree = roxmltree::Document::parse_with_options(&content, opts)?;
@@ -285,7 +285,7 @@ impl EntityResolver {
})
}
- fn resolve(&mut self, uri: &str) -> core::result::Result<Option<&'static str>, String> {
+ fn resolve(&self, uri: &str) -> core::result::Result<Option<&str>, String> {
// Load full path.
let full_path = self.resolve_full_path(uri)?;
@@ -294,90 +294,9 @@ impl EntityResolver {
return Ok(None);
}
- // Get metadata.
- let entity_file_metadata = match fs::metadata(&full_path) {
- Ok(m) => m,
- Err(e) => {
- return Err(format!(
- "failed to get metadata of entity file {}: {}",
- full_path.display(),
- e
- ))
- }
- };
- let entity_file_size = entity_file_metadata.len();
-
- // Make sure the file size is reasonable.
- if entity_file_size > self.file_length_limit {
- return Err(format!(
- "entity file {} is too large ({} bytes)",
- full_path.display(),
- entity_file_size
- ));
- }
-
- // Make sure the allocated size is reasonable.
- let entity_file_allocated_size = self.bump.allocated_bytes() as u64;
- if entity_file_allocated_size + entity_file_size > self.allocated_size_limit {
- return Err(format!(
- "entity resolver has no more memory (allocated {} bytes, entity file size {} bytes)",
- entity_file_allocated_size,
- entity_file_size,
- ));
- }
-
- // Allocate memory in the bump arena.
- if entity_file_size == 0 {
- return Ok(Some(""));
- }
- let layout = std::alloc::Layout::from_size_align(entity_file_size as usize, 1)
- .expect("Failed to create layout for entity file content");
- let entity_file_content_ptr = self.bump.alloc_layout(layout).as_ptr() as *mut u8;
-
- // Read the file content into the allocated memory.
- //
- // SAFETY: We have allocated enough memory for the file content already.
- unsafe {
- let entity_file_content_slice =
- std::slice::from_raw_parts_mut(entity_file_content_ptr, entity_file_size as usize);
- fs::File::open(&full_path)
- .map_err(|e| {
- format!(
- "Failed to open entity file (path {}): {}",
- full_path.display(),
- e
- )
- })?
- .read_exact(entity_file_content_slice)
- .map_err(|e| {
- format!(
- "Failed to read entity file content (path {}): {}",
- full_path.display(),
- e
- )
- })?;
- }
-
- // Make sure the content is valid UTF-8.
- let entity_file_content = unsafe {
- std::str::from_utf8(std::slice::from_raw_parts(
- entity_file_content_ptr,
- entity_file_size as usize,
- ))
- };
- let result = match entity_file_content {
- Ok(s) => s,
- Err(e) => {
- return Err(format!(
- "entity file {} contains invalid UTF-8: {}",
- full_path.display(),
- e
- ))
- }
- };
+ let buf = fs::read_to_string(&full_path).map_err(|e| format!("failed to read entity file {}: {}", full_path.display(), e))?;
- // Return the content.
- Ok(Some(result))
+ Ok(Some(self.bump.alloc_str(&buf)))
}
fn resolve_full_path(&self, uri: &str) -> core::result::Result<PathBuf, String> {(You can keep the size tracking, but you will have to reimplement it using interior mutability, e.g. via |
|
@RazrFalcon I don't think version 0.21.0 was fit for purpose after all. Relaxing the implicit |
|
Sounds good to me. 👍 |
I try and now |
|
Hello, it works well with really HDFS service now. Cannot wait for new release ❤️ |
|
Released to crates.io as 0.21.0 and yanked 0.21.0. |
Version 0.21.0 was yanked. See: RazrFalcon/roxmltree#149
No description provided.