use std::num::NonZero;
use crate::{
macros::all_option_tuples,
result::{ResultComp, ResultCompErr},
structs,
traits::Buffer,
types,
};
#[derive(Debug, Clone)]
pub struct GetParam {
pub md: structs::MQMD,
pub gmo: structs::MQGMO,
}
pub trait GetValue<'b, R, B>: std::marker::Sized {
type Error: std::fmt::Debug;
fn get_consume<F>(param: &mut GetParam, get: F) -> ResultCompErr<Self, Self::Error>
where
F: FnOnce(&mut GetParam) -> ResultComp<GetState<B>>,
B: Buffer<'b, R>;
#[must_use]
#[inline]
fn get_max_data_size() -> Option<NonZero<usize>> {
None
}
}
#[diagnostic::on_unimplemented(message = "{Self} does not implement `GetOption` so it can't be used as an argument for MQI get")]
pub trait GetOption {
fn apply_param(&self, param: &mut GetParam);
}
pub trait GetAttr<'b, R> {
fn get_extract<F, B>(param: &mut GetParam, get: F) -> ResultComp<(Self, GetState<B>)>
where
F: FnOnce(&mut GetParam) -> ResultComp<GetState<B>>,
B: Buffer<'b, R>,
Self: Sized;
}
#[cfg(feature = "mqai")]
pub trait GetBagAttr {
fn get_bag_extract<F>(param: &mut GetParam, mqi: F) -> ResultComp<Self>
where
F: FnOnce(&mut GetParam) -> ResultComp<()>,
Self: Sized;
}
#[derive(Debug, Clone)]
pub struct GetState<B> {
pub buffer: B,
pub data_length: usize,
pub message_length: usize,
pub format: types::MessageFormat,
}
impl<B> GetState<B> {
pub fn into_truncated_buffer<'b, R>(self) -> B
where
B: Buffer<'b, R>,
{
self.buffer.truncate(self.data_length)
}
}
all_option_tuples!(GetOption, GetParam);