diff --git a/deflate/flate2.cc b/deflate/flate2.cc index 0b147a8..e6deb8c 100644 --- a/deflate/flate2.cc +++ b/deflate/flate2.cc @@ -11,6 +11,8 @@ #include "absl/strings/cord.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" +#include "support/rs_std/result.h" +#include "support/rs_std/unit.h" namespace security::deflate { @@ -146,7 +148,7 @@ std::optional GzDecoderImpl::header() const { template absl::Status GzDecoderImpl::write_all(absl::string_view data) { - rs_std::Result result_unit = + rs_std::Result result_unit = decoder_.write_all(absl::Span( reinterpret_cast(data.data()), data.size())); if (!result_unit.has_value()) { @@ -184,7 +186,7 @@ GzEncoder GzEncoder::create(Compression level) { } absl::Status GzEncoder::write_all(absl::string_view data) { - rs_std::Result result_unit = + rs_std::Result result_unit = encoder_.write_all(absl::Span( reinterpret_cast(data.data()), data.size())); if (!result_unit.has_value()) { diff --git a/deflate/rust/gz/write.rs b/deflate/rust/gz/write.rs index e106896..64decf1 100644 --- a/deflate/rust/gz/write.rs +++ b/deflate/rust/gz/write.rs @@ -7,11 +7,10 @@ use std::io::Write; use crate::vec_u8::VecU8; use crate::Compression; -// NOTE: b/517030085 - Crubit doesn't seem to support the unit type here, so using a u8 for now. -fn write_all_impl(writer: &mut Option, bytes: &[u8]) -> Result { +fn write_all_impl(writer: &mut Option, bytes: &[u8]) -> Result<(), VecU8> { if let Some(writer) = writer { match writer.write_all(bytes) { - Ok(()) => Ok(0), + Ok(()) => Ok(()), Err(e) => Err(VecU8::from(e.to_string())), } } else { @@ -51,7 +50,7 @@ impl GzDecoder { } /// Attempts to write an entire buffer into this writer. - pub fn write_all(&mut self, buf: &[u8]) -> Result { + pub fn write_all(&mut self, buf: &[u8]) -> Result<(), VecU8> { write_all_impl(&mut self.writer, buf) } @@ -73,7 +72,7 @@ impl GzEncoder { } /// Attempts to write an entire buffer into this writer. - pub fn write_all(&mut self, buf: &[u8]) -> Result { + pub fn write_all(&mut self, buf: &[u8]) -> Result<(), VecU8> { write_all_impl(&mut self.writer, buf) } @@ -99,7 +98,7 @@ impl MultiGzDecoder { } /// Attempts to write an entire buffer into this writer. - pub fn write_all(&mut self, buf: &[u8]) -> Result { + pub fn write_all(&mut self, buf: &[u8]) -> Result<(), VecU8> { write_all_impl(&mut self.writer, buf) } diff --git a/leveldb/rust/cpp_cmp.h b/leveldb/rust/cpp_cmp.h index f7eec02..c117891 100644 --- a/leveldb/rust/cpp_cmp.h +++ b/leveldb/rust/cpp_cmp.h @@ -5,7 +5,7 @@ #include #include "absl/types/span.h" -#include "third_party/crubit/support/annotations.h" +#include "support/annotations.h" namespace leveldb_rs { diff --git a/leveldb/rust/cpp_env.h b/leveldb/rust/cpp_env.h index 6054455..22a9a55 100644 --- a/leveldb/rust/cpp_env.h +++ b/leveldb/rust/cpp_env.h @@ -16,7 +16,7 @@ #include "absl/time/clock.h" #include "absl/time/time.h" #include "absl/types/span.h" -#include "third_party/crubit/support/annotations.h" +#include "support/annotations.h" namespace leveldb_rs { diff --git a/leveldb/rust/cpp_filter.h b/leveldb/rust/cpp_filter.h index 55bedf1..67d75e9 100644 --- a/leveldb/rust/cpp_filter.h +++ b/leveldb/rust/cpp_filter.h @@ -6,7 +6,7 @@ #include "absl/strings/string_view.h" #include "absl/types/span.h" -#include "third_party/crubit/support/annotations.h" +#include "support/annotations.h" namespace leveldb_rs { diff --git a/leveldb/rust/cpp_logger.h b/leveldb/rust/cpp_logger.h index 8890c8d..2e840cf 100644 --- a/leveldb/rust/cpp_logger.h +++ b/leveldb/rust/cpp_logger.h @@ -2,7 +2,7 @@ #define SECURITY_LEVELDB_RUST_CPP_LOGGER_H_ #include "absl/strings/string_view.h" -#include "third_party/crubit/support/annotations.h" +#include "support/annotations.h" namespace leveldb_rs { diff --git a/leveldb/rust/db_impl.rs b/leveldb/rust/db_impl.rs index 8007240..8a25918 100644 --- a/leveldb/rust/db_impl.rs +++ b/leveldb/rust/db_impl.rs @@ -82,7 +82,7 @@ impl DB { .map_err(|e| e.into()) } - pub fn close(&self) -> Result { + pub fn close(&self) -> Result<(), LevelDBError> { let mut guard = match self.db.lock() { Ok(g) => g, Err(e) => return Err(LevelDBError::from(format!("poisoned lock: {}", e))), @@ -91,14 +91,13 @@ impl DB { .take() .ok_or_else(|| LevelDBError::from("DB is not open")) .and_then(|mut db| db.close().map_err(|e| e.into())) - .map(|_| 0) .map_err(|e| e.into()) } - pub fn put(&self, k: &[u8], v: &[u8]) -> Result { + pub fn put(&self, k: &[u8], v: &[u8]) -> Result<(), LevelDBError> { // put performs a deep copy, no references are leaked. let mut guard = self.get_db()?; - guard.put(k, v).map(|_| 0).map_err(|e| e.into()) + guard.put(k, v).map_err(|e| e.into()) } pub fn get(&self, k: &[u8]) -> Result, LevelDBError> { @@ -106,19 +105,19 @@ impl DB { Ok(guard.get(k).map(|v| DBValue { inner: v })) } - pub fn delete(&self, k: &[u8]) -> Result { + pub fn delete(&self, k: &[u8]) -> Result<(), LevelDBError> { let mut guard = self.get_db()?; - guard.delete(k).map(|_| 0).map_err(|e| e.into()) + guard.delete(k).map_err(|e| e.into()) } - pub fn flush(&self) -> Result { + pub fn flush(&self) -> Result<(), LevelDBError> { let mut guard = self.get_db()?; - guard.flush().map(|_| 0).map_err(|e| e.into()) + guard.flush().map_err(|e| e.into()) } - pub fn write(&self, batch: WriteBatch, sync: bool) -> Result { + pub fn write(&self, batch: WriteBatch, sync: bool) -> Result<(), LevelDBError> { let mut guard = self.get_db()?; - guard.write(batch.batch, sync).map(|_| 0).map_err(|e| e.into()) + guard.write(batch.batch, sync).map_err(|e| e.into()) } pub fn get_snapshot(&self) -> Result { @@ -148,8 +147,8 @@ impl DB { guard.new_iter_at(s).map(|iter| DBIterator { iterator: Some(iter) }).map_err(|e| e.into()) } - pub fn compact_range(&self, start: &[u8], end: &[u8]) -> Result { + pub fn compact_range(&self, start: &[u8], end: &[u8]) -> Result<(), LevelDBError> { let mut guard = self.get_db()?; - guard.compact_range(start, end).map(|_| 0).map_err(|e| e.into()) + guard.compact_range(start, end).map_err(|e| e.into()) } } diff --git a/pixel_bridge/rust/image.rs b/pixel_bridge/rust/image.rs index 4d64124..baa929b 100644 --- a/pixel_bridge/rust/image.rs +++ b/pixel_bridge/rust/image.rs @@ -133,12 +133,11 @@ impl std::fmt::Debug for ImageDecoder { } } -// NOTE: b/517030085 - Crubit doesn't seem to support () here, so using a u8 for now. -pub type Status = Result; +pub type Status = Result<(), VecU8>; #[inline(always)] fn ok() -> Status { - Ok(0) + Ok(()) } #[inline(always)] diff --git a/serde_json/rust/json.rs b/serde_json/rust/json.rs index 4cd16b7..f2a863e 100644 --- a/serde_json/rust/json.rs +++ b/serde_json/rust/json.rs @@ -1,12 +1,11 @@ use crate::make_vec_type; use crate::raw_string::RawString; use serde::Serialize; -// NOTE: b/517030085 - Crubit doesn't seem to support () here, so using a u8 for now. -pub type Status = Result; +pub type Status = Result<(), RawString>; #[inline(always)] fn ok() -> Status { - Ok(0) + Ok(()) } #[inline(always)] diff --git a/zip/converters.cc b/zip/converters.cc index 9c5eaa5..faac231 100644 --- a/zip/converters.cc +++ b/zip/converters.cc @@ -1,6 +1,5 @@ #include "converters.h" -#include #include #include @@ -8,6 +7,8 @@ #include "crubit/rust.h" #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "support/rs_std/result.h" +#include "support/rs_std/unit.h" namespace security::zip { @@ -43,7 +44,7 @@ absl::StatusOr FromRustResultVecU8( } absl::Status FromRustResultUnit( - rs_std::Result result_unit) { + rs_std::Result result_unit) { if (!result_unit.has_value()) { return ZipErrorToStatus(std::move(result_unit).err()); } diff --git a/zip/converters.h b/zip/converters.h index f21704e..626764c 100644 --- a/zip/converters.h +++ b/zip/converters.h @@ -1,7 +1,6 @@ #ifndef SECURITY_ZIP_CONVERTERS_H_ #define SECURITY_ZIP_CONVERTERS_H_ -#include #include #include "crubit_helpers/string_conversions.h" @@ -10,6 +9,8 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" +#include "support/rs_std/result.h" +#include "support/rs_std/unit.h" namespace security::zip { @@ -32,7 +33,7 @@ class RustVecU8Wrapper { absl::StatusOr FromRustResultVecU8( rs_std::Result result_vec_u8); absl::Status FromRustResultUnit( - rs_std::Result result_unit); + rs_std::Result result_unit); absl::StatusOr FromRustBufferedZipArchive( rs_std::Result diff --git a/zip/rust/write.rs b/zip/rust/write.rs index bcdcef8..a9b77af 100644 --- a/zip/rust/write.rs +++ b/zip/rust/write.rs @@ -228,7 +228,7 @@ impl BufferedZipWriter { &mut self, name: &[u8], options: ZipWriterFileOptions, - ) -> Result { + ) -> Result<(), ZipError> { start_file_impl(&mut self.writer, name, options) } @@ -237,12 +237,12 @@ impl BufferedZipWriter { &mut self, name: &[u8], options: ZipWriterFileOptions, - ) -> Result { + ) -> Result<(), ZipError> { add_directory_impl(&mut self.writer, name, options) } /// Writes data to the current file in the zip archive. - pub fn write_data(&mut self, data: VecU8) -> Result { + pub fn write_data(&mut self, data: VecU8) -> Result<(), ZipError> { write_data_impl(&mut self.writer, data) } @@ -253,17 +253,17 @@ impl BufferedZipWriter { pub fn write_buffered_zip_file_content( &mut self, file: &mut BufferedZipFile, - ) -> Result { + ) -> Result<(), ZipError> { do_copy_impl(&mut self.writer, file) } /// Writes file content from a `FsZipFile` to the current file in the zip archive. - pub fn write_fs_zip_file_content(&mut self, file: &mut FsZipFile) -> Result { + pub fn write_fs_zip_file_content(&mut self, file: &mut FsZipFile) -> Result<(), ZipError> { do_copy_impl(&mut self.writer, file) } /// Writes file content from a path to the current file in the zip archive. - pub fn write_file_content(&mut self, path: &[u8]) -> Result { + pub fn write_file_content(&mut self, path: &[u8]) -> Result<(), ZipError> { write_file_content_impl(&mut self.writer, path) } } @@ -336,11 +336,10 @@ impl FsZipWriter { } /// Finishes writing the zip archive to file. - // NOTE: b/517030085 - Crubit doesn't seem to support the unit type here, so using a u8 for now. - pub fn finish(&mut self) -> Result { + pub fn finish(&mut self) -> Result<(), ZipError> { if let Some(writer) = self.writer.take() { match writer.finish() { - Ok(_) => Ok(0), + Ok(_) => Ok(()), Err(e) => Err(ZipError::internal(e.to_string())), } } else { @@ -353,7 +352,7 @@ impl FsZipWriter { &mut self, name: &[u8], options: ZipWriterFileOptions, - ) -> Result { + ) -> Result<(), ZipError> { start_file_impl(&mut self.writer, name, options) } @@ -362,12 +361,12 @@ impl FsZipWriter { &mut self, name: &[u8], options: ZipWriterFileOptions, - ) -> Result { + ) -> Result<(), ZipError> { add_directory_impl(&mut self.writer, name, options) } /// Writes data to the current file in the zip archive. - pub fn write_data(&mut self, data: VecU8) -> Result { + pub fn write_data(&mut self, data: VecU8) -> Result<(), ZipError> { write_data_impl(&mut self.writer, data) } @@ -378,33 +377,32 @@ impl FsZipWriter { pub fn write_buffered_zip_file_content( &mut self, file: &mut BufferedZipFile, - ) -> Result { + ) -> Result<(), ZipError> { do_copy_impl(&mut self.writer, file) } /// Writes file content from a `FsZipFile` to the current file in the zip archive. - pub fn write_fs_zip_file_content(&mut self, file: &mut FsZipFile) -> Result { + pub fn write_fs_zip_file_content(&mut self, file: &mut FsZipFile) -> Result<(), ZipError> { do_copy_impl(&mut self.writer, file) } /// Writes file content from a path to the current file in the zip archive. - pub fn write_file_content(&mut self, path: &[u8]) -> Result { + pub fn write_file_content(&mut self, path: &[u8]) -> Result<(), ZipError> { write_file_content_impl(&mut self.writer, path) } } -// NOTE: b/517030085 - Crubit doesn't seem to support the unit type here, so using a u8 for now. fn start_file_impl( writer: &mut Option>, name: &[u8], options: ZipWriterFileOptions, -) -> Result { +) -> Result<(), ZipError> { if let Some(writer) = writer.as_mut() { let name_lossy = String::from_utf8_lossy(name); let name_str = name_lossy.as_ref(); match FileOptions::try_from(&options) { Ok(file_options) => match writer.start_file(name_str, file_options) { - Ok(_) => Ok(0), + Ok(_) => Ok(()), Err(e) => Err(ZipError::internal(e.to_string())), }, Err(e) => Err(ZipError::invalid_argument(e.to_string())), @@ -414,18 +412,17 @@ fn start_file_impl( } } -// NOTE: b/517030085 - Crubit doesn't seem to support the unit type here, so using a u8 for now. fn add_directory_impl( writer: &mut Option>, name: &[u8], options: ZipWriterFileOptions, -) -> Result { +) -> Result<(), ZipError> { if let Some(writer) = writer.as_mut() { let name_lossy = String::from_utf8_lossy(name); let name_str = name_lossy.as_ref(); match FileOptions::try_from(&options) { Ok(file_options) => match writer.add_directory(name_str, file_options) { - Ok(_) => Ok(0), + Ok(_) => Ok(()), Err(e) => Err(ZipError::internal(e.to_string())), }, Err(e) => Err(ZipError::invalid_argument(e.to_string())), @@ -435,14 +432,13 @@ fn add_directory_impl( } } -// NOTE: b/517030085 - Crubit doesn't seem to support the unit type here, so using a u8 for now. fn write_data_impl( writer: &mut Option>, data: VecU8, -) -> Result { +) -> Result<(), ZipError> { if let Some(writer) = writer.as_mut() { match writer.write_all(data.as_slice()) { - Ok(_) => Ok(0), + Ok(_) => Ok(()), Err(e) => Err(ZipError::internal(e.to_string())), } } else { @@ -450,14 +446,13 @@ fn write_data_impl( } } -// NOTE: b/517030085 - Crubit doesn't seem to support the unit type here, so using a u8 for now. fn do_copy_impl( writer: &mut Option>, reader: &mut R, -) -> Result { +) -> Result<(), ZipError> { if let Some(writer) = writer.as_mut() { match copy(reader, writer) { - Ok(_) => Ok(0), + Ok(_) => Ok(()), Err(e) => Err(ZipError::internal(e.to_string())), } } else { @@ -465,17 +460,16 @@ fn do_copy_impl( } } -// NOTE: b/517030085 - Crubit doesn't seem to support the unit type here, so using a u8 for now. fn write_file_content_impl( writer: &mut Option>, path: &[u8], -) -> Result { +) -> Result<(), ZipError> { if let Some(writer) = writer.as_mut() { let path_lossy = String::from_utf8_lossy(path); let path_str = path_lossy.as_ref(); match File::open(path_str) { Ok(mut file) => match copy(&mut file, writer) { - Ok(_) => Ok(0), + Ok(_) => Ok(()), Err(e) => Err(ZipError::internal(e.to_string())), }, Err(e) => Err(ZipError::internal(e.to_string())),