Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions deflate/flate2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -146,7 +148,7 @@ std::optional<GzHeader> GzDecoderImpl<RustDecoder>::header() const {

template <typename RustDecoder>
absl::Status GzDecoderImpl<RustDecoder>::write_all(absl::string_view data) {
rs_std::Result<uint8_t, rust::vec_u8::VecU8> result_unit =
rs_std::Result<rs_std::unit_t, rust::vec_u8::VecU8> result_unit =
decoder_.write_all(absl::Span<const uint8_t>(
reinterpret_cast<const uint8_t*>(data.data()), data.size()));
if (!result_unit.has_value()) {
Expand Down Expand Up @@ -184,7 +186,7 @@ GzEncoder GzEncoder::create(Compression level) {
}

absl::Status GzEncoder::write_all(absl::string_view data) {
rs_std::Result<uint8_t, rust::vec_u8::VecU8> result_unit =
rs_std::Result<rs_std::unit_t, rust::vec_u8::VecU8> result_unit =
encoder_.write_all(absl::Span<const uint8_t>(
reinterpret_cast<const uint8_t*>(data.data()), data.size()));
if (!result_unit.has_value()) {
Expand Down
11 changes: 5 additions & 6 deletions deflate/rust/gz/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<W: Write>(writer: &mut Option<W>, bytes: &[u8]) -> Result<u8, VecU8> {
fn write_all_impl<W: Write>(writer: &mut Option<W>, 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 {
Expand Down Expand Up @@ -51,7 +50,7 @@ impl GzDecoder {
}

/// Attempts to write an entire buffer into this writer.
pub fn write_all(&mut self, buf: &[u8]) -> Result<u8, VecU8> {
pub fn write_all(&mut self, buf: &[u8]) -> Result<(), VecU8> {
write_all_impl(&mut self.writer, buf)
}

Expand All @@ -73,7 +72,7 @@ impl GzEncoder {
}

/// Attempts to write an entire buffer into this writer.
pub fn write_all(&mut self, buf: &[u8]) -> Result<u8, VecU8> {
pub fn write_all(&mut self, buf: &[u8]) -> Result<(), VecU8> {
write_all_impl(&mut self.writer, buf)
}

Expand All @@ -99,7 +98,7 @@ impl MultiGzDecoder {
}

/// Attempts to write an entire buffer into this writer.
pub fn write_all(&mut self, buf: &[u8]) -> Result<u8, VecU8> {
pub fn write_all(&mut self, buf: &[u8]) -> Result<(), VecU8> {
write_all_impl(&mut self.writer, buf)
}

Expand Down
2 changes: 1 addition & 1 deletion leveldb/rust/cpp_cmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>

#include "absl/types/span.h"
#include "third_party/crubit/support/annotations.h"
#include "support/annotations.h"

namespace leveldb_rs {

Expand Down
2 changes: 1 addition & 1 deletion leveldb/rust/cpp_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion leveldb/rust/cpp_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion leveldb/rust/cpp_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
23 changes: 11 additions & 12 deletions leveldb/rust/db_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl DB {
.map_err(|e| e.into())
}

pub fn close(&self) -> Result<u8, LevelDBError> {
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))),
Expand All @@ -91,34 +91,33 @@ 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<u8, LevelDBError> {
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<Option<DBValue>, LevelDBError> {
let mut guard = self.get_db()?;
Ok(guard.get(k).map(|v| DBValue { inner: v }))
}

pub fn delete(&self, k: &[u8]) -> Result<u8, LevelDBError> {
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<u8, LevelDBError> {
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<u8, LevelDBError> {
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<Snapshot, LevelDBError> {
Expand Down Expand Up @@ -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<u8, LevelDBError> {
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())
}
}
5 changes: 2 additions & 3 deletions pixel_bridge/rust/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8, VecU8>;
pub type Status = Result<(), VecU8>;

#[inline(always)]
fn ok() -> Status {
Ok(0)
Ok(())
}

#[inline(always)]
Expand Down
5 changes: 2 additions & 3 deletions serde_json/rust/json.rs
Original file line number Diff line number Diff line change
@@ -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<u8, RawString>;
pub type Status = Result<(), RawString>;

#[inline(always)]
fn ok() -> Status {
Ok(0)
Ok(())
}

#[inline(always)]
Expand Down
5 changes: 3 additions & 2 deletions zip/converters.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "converters.h"

#include <cstdint>
#include <string>
#include <utility>

#include "crubit_helpers/string_conversions.h"
#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 {

Expand Down Expand Up @@ -43,7 +44,7 @@ absl::StatusOr<RustVecU8Wrapper> FromRustResultVecU8(
}

absl::Status FromRustResultUnit(
rs_std::Result<uint8_t, rust::ZipError> result_unit) {
rs_std::Result<rs_std::unit_t, rust::ZipError> result_unit) {
if (!result_unit.has_value()) {
return ZipErrorToStatus(std::move(result_unit).err());
}
Expand Down
5 changes: 3 additions & 2 deletions zip/converters.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef SECURITY_ZIP_CONVERTERS_H_
#define SECURITY_ZIP_CONVERTERS_H_

#include <cstdint>
#include <utility>

#include "crubit_helpers/string_conversions.h"
Expand All @@ -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 {

Expand All @@ -32,7 +33,7 @@ class RustVecU8Wrapper {
absl::StatusOr<RustVecU8Wrapper> FromRustResultVecU8(
rs_std::Result<rust::VecU8, rust::ZipError> result_vec_u8);
absl::Status FromRustResultUnit(
rs_std::Result<uint8_t, rust::ZipError> result_unit);
rs_std::Result<rs_std::unit_t, rust::ZipError> result_unit);

absl::StatusOr<rust::BufferedZipArchive> FromRustBufferedZipArchive(
rs_std::Result<rust::BufferedZipArchive, rust::ZipError>
Expand Down
Loading
Loading