Skip to content

The DataSource API #6

@rileyshahar

Description

@rileyshahar

I figure this is a good place to have a discussion about this API. Here's the current code, for reference:

pub trait DataSource {
// constructors are left to each implementation, once you have one, you can:
fn read(&self, offset: usize, length: usize, buffer: &mut Vec<u8>) -> Result<(), &str>;
fn write(&self, offset: usize, length: usize, buffer: &mut Vec<u8>) -> Result<(), &str>;
fn flush(&self, offset: usize, length: usize) -> Result<(), &str>;
fn add_map(
&self,
with_flag: Flags,
into_address_space: &mut AddressSpace,
offset: usize,
length: usize,
) -> Result<usize, &str>;
fn del_map(
&self,
from_address_space: &mut AddressSpace,
offset: usize,
length: usize,
) -> Result<(), &str>;
}

Some questions I have:

  1. Do we want to force the error type to be &str, or do we want to allow each implementer to provide their own error type? The latter is maybe slightly more complicated, but much, much more idiomatic.
  2. Why does write need mutable access to the buffer? Very possible I'm misunderstanding, but my assumption would be it just needs to read out of the buffer so it can write that data into whatever its backing memory is.
  3. Is there a reason we need to take a &mut Vec<u8> instead of &mut [u8]? My instinct is the latter is more general (since a &mut Vec can be downcast into a mutable slice, but not vice versa), but open to other considerations.

Happy to write a PR to resolve any/all of these, but wanted to raise them first, since they're more fluid design choices then my other PRs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions