Skip to main content

InMemoryStorage

Struct InMemoryStorage 

Source
pub struct InMemoryStorage { /* private fields */ }
Expand description

In-memory storage with automatic spillover to tempfiles for large objects.

Thread-safe: uses DashMap for concurrent access. Objects larger than the configured max_memory_size are transparently written to temporary files and read back on demand.

§Examples

use bytes::Bytes;
use rustack_s3_core::storage::InMemoryStorage;

let storage = InMemoryStorage::new(1024);
let result = storage
    .write_object("my-bucket", "hello.txt", "null", Bytes::from("hello"))
    .await
    .unwrap();
assert_eq!(result.size, 5);

let data = storage
    .read_object("my-bucket", "hello.txt", "null", None)
    .await
    .unwrap();
assert_eq!(data.as_ref(), b"hello");

Implementations§

Source§

impl InMemoryStorage

Source

pub fn new(max_memory_size: usize) -> Self

Create a new storage backend with the given memory threshold.

Objects larger than max_memory_size bytes are spilled to temporary files on disk.

Source

pub fn default_max_memory_size() -> usize

Return the default maximum in-memory object size (512 KiB).

Source

pub async fn write_object( &self, bucket: &str, key: &str, version_id: &str, data: Bytes, ) -> Result<WriteResult, S3ServiceError>

Store object data. Computes MD5 and returns a WriteResult.

If the data exceeds the configured memory threshold, it is spilled to a temporary file on disk.

§Errors

Returns S3ServiceError::Internal if the temporary file cannot be created or written.

Source

pub async fn read_object( &self, bucket: &str, key: &str, version_id: &str, range: Option<(u64, u64)>, ) -> Result<Bytes, S3ServiceError>

Read object data. Returns the full Bytes for the object.

If range is specified as (start, end) (inclusive on both ends), only that byte range is returned.

§Errors
Source

pub async fn copy_object( &self, src_bucket: &str, src_key: &str, src_version_id: &str, dst_bucket: &str, dst_key: &str, dst_version_id: &str, ) -> Result<WriteResult, S3ServiceError>

Copy object data from one location to another.

Reads the source object data, then writes it to the destination location. Returns a WriteResult for the destination object.

§Errors
Source

pub fn delete_object(&self, bucket: &str, key: &str, version_id: &str)

Delete object data.

Removes the stored data for the given object key. If the data was on disk, the temporary file is cleaned up via the Drop implementation. This is a no-op if the object does not exist.

Source

pub async fn write_part( &self, bucket: &str, upload_id: &str, part_number: u32, data: Bytes, ) -> Result<WriteResult, S3ServiceError>

Store a multipart part.

Computes MD5 and returns a WriteResult. If the part data exceeds the memory threshold, it is spilled to a temporary file.

§Errors

Returns S3ServiceError::Internal if the temporary file cannot be created or written.

Source

pub async fn read_part( &self, bucket: &str, upload_id: &str, part_number: u32, ) -> Result<Bytes, S3ServiceError>

Read a multipart part’s data.

§Errors
Source

pub async fn complete_multipart( &self, bucket: &str, upload_id: &str, key: &str, version_id: &str, part_numbers: &[u32], ) -> Result<(WriteResult, Vec<String>), S3ServiceError>

Assemble parts into a final object. Concatenates part data in order.

Returns a tuple of (WriteResult, Vec<String>) where the vector contains the individual (unquoted) MD5 hex digests for each part. The WriteResult::etag is a composite ETag in the format "<md5>-<part_count>".

§Errors
Source

pub fn abort_multipart(&self, bucket: &str, upload_id: &str)

Delete all parts for a multipart upload.

Removes all stored part data associated with the given upload ID. Temporary files are cleaned up automatically via Drop.

Source

pub fn delete_bucket_data(&self, bucket: &str)

Delete all data (objects and parts) for a bucket.

This removes both object data and any in-progress multipart part data associated with the bucket.

Source

pub fn reset(&self)

Reset all storage, removing every object and part.

Trait Implementations§

Source§

impl Debug for InMemoryStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InMemoryStorage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more