mirror of
https://github.com/bspeice/aeron-rs
synced 2024-12-21 21:38:09 -05:00
Nicer flyweight API
This commit is contained in:
parent
5725c32c72
commit
88985418e0
@ -11,20 +11,30 @@ where
|
|||||||
_phantom: PhantomData<S>,
|
_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>
|
impl<A, S> Flyweight<A, S>
|
||||||
where
|
where
|
||||||
A: AtomicBuffer,
|
A: AtomicBuffer,
|
||||||
S: Sized,
|
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 {
|
pub(crate) fn get_struct(&self) -> &S {
|
||||||
// UNWRAP: Bounds check performed during initialization
|
// UNWRAP: Bounds check performed during initialization
|
||||||
self.buffer.overlay::<S>(self.base_offset).unwrap()
|
self.buffer.overlay::<S>(self.base_offset).unwrap()
|
||||||
|
@ -36,9 +36,8 @@ where
|
|||||||
pub fn terminate_driver(&mut self, _token_buffer: Option<&[u8]>) -> Result<()> {
|
pub fn terminate_driver(&mut self, _token_buffer: Option<&[u8]>) -> Result<()> {
|
||||||
let _client_id = self.client_id;
|
let _client_id = self.client_id;
|
||||||
self.write_command_to_driver(|buffer: &mut [u8], _length: &mut IndexT| {
|
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`
|
// 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
|
// FIXME: Uncommenting this causes termination to not succeed
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user