mirror of
https://github.com/bspeice/aeron-rs
synced 2024-12-21 05:28:10 -05:00
Nicer flyweight API
This commit is contained in:
parent
5725c32c72
commit
88985418e0
@ -11,20 +11,30 @@ where
|
||||
_phantom: PhantomData<S>,
|
||||
}
|
||||
|
||||
pub struct Unchecked;
|
||||
|
||||
impl<A> Flyweight<A, Unchecked>
|
||||
where
|
||||
A: AtomicBuffer,
|
||||
{
|
||||
pub fn new<S>(buffer: A, offset: IndexT) -> Result<Flyweight<A, S>>
|
||||
where
|
||||
S: Sized
|
||||
{
|
||||
buffer.overlay::<S>(offset)?;
|
||||
Ok(Flyweight {
|
||||
buffer,
|
||||
base_offset: offset,
|
||||
_phantom: PhantomData
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, S> Flyweight<A, S>
|
||||
where
|
||||
A: AtomicBuffer,
|
||||
S: Sized,
|
||||
{
|
||||
pub fn new(buffer: A, offset: IndexT) -> Result<Flyweight<A, S>> {
|
||||
buffer.overlay::<S>(offset)?;
|
||||
Ok(Flyweight {
|
||||
buffer,
|
||||
base_offset: offset,
|
||||
_phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn get_struct(&self) -> &S {
|
||||
// UNWRAP: Bounds check performed during initialization
|
||||
self.buffer.overlay::<S>(self.base_offset).unwrap()
|
||||
|
@ -36,9 +36,8 @@ where
|
||||
pub fn terminate_driver(&mut self, _token_buffer: Option<&[u8]>) -> Result<()> {
|
||||
let _client_id = self.client_id;
|
||||
self.write_command_to_driver(|buffer: &mut [u8], _length: &mut IndexT| {
|
||||
// FIXME: This method signature is ugly.
|
||||
// UNWRAP: Buffer from `write_command` guaranteed to be long enough for `TerminateDriverDefn`
|
||||
let _request: Flyweight<_, TerminateDriverDefn> = Flyweight::new(buffer, 0).unwrap();
|
||||
let _request = Flyweight::new::<TerminateDriverDefn>(buffer, 0).unwrap();
|
||||
|
||||
// FIXME: Uncommenting this causes termination to not succeed
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user