Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ReadPos/Slice generic over Borrow and PosRead #1

Merged
merged 16 commits into from
May 17, 2018
Merged

Conversation

dekellum
Copy link
Owner

@dekellum dekellum commented May 11, 2018

WIP, will summarize.

As of 7e02853, ReadPos (and ReadSlice) are now generic over a Barrow and PosRead type, in the form:

pub struct ReadPos<P, B>
where P: PosRead, B: Borrow<P>

This allows ReadPos/Slice to support, for example, an owned file (ReadPos<File, File>) as well as by shared reference (ReadPos<File, &File> or ReadPos<File, Arc<File>>. It also makes it possible for other (future) implementations of PosRead to share these types.

For all but the owned case, a type is needed for P which can not be inferred, e.g.

ReadPos::<File, _>::new(Arc::new(f), 10)

The existing rs::Read* types are left in place by type alias, e.g.:

pub type ReadSlice = super::ReadSlice<File, Arc<File>>;

This has been simplified, see update below.

A new ReadSubSlice trait must be imported to continue to use subslice. This is, strictly-speaking a breaking change.

@dekellum dekellum changed the title Make ReadPos/Slice generic over Borrow<File> Make ReadPos/Slice generic over Borrow and PosRead May 16, 2018
@dekellum
Copy link
Owner Author

dekellum commented May 17, 2018

As of 58b1f26, PosRead has been implemented over all Borrow<File>, such that ReadPos (and ReadSlice) are now more simply generic over PosRead and have form:

pub struct ReadPos<P>
where P: PosRead

So these can own, for example via ReadPos<File> or use a shared reference, as in ReadPos<&File> or ReadPos<Arc<File>> and there is no type inference challenges.

The existing rc::Read* types are left in place by type alias, e.g.:

pub type ReadSlice = super::ReadSlice<Arc<File>>;

@dekellum dekellum merged commit 10325e8 into master May 17, 2018
@dekellum
Copy link
Owner Author

Dropped ReadSubSlice trait, the only remaining breaking change for this, in 664a71c and merged in fc3a82d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant