use libmqm_default as default;
use super::option;
use crate::{
Object,
connection::AsConnection,
constants,
prelude::*,
result::{ResultComp, ResultCompErr},
structs, types,
};
impl<C: AsConnection> Object<C> {
pub fn open<'oo>(connection: C, open_option: &impl option::OpenOption<'oo, types::MQOO>) -> ResultComp<Self> {
Self::open_as(connection, open_option)
}
pub fn open_with<'oo, A>(connection: C, open_option: &impl option::OpenOption<'oo, types::MQOO>) -> ResultComp<(Self, A)>
where
A: option::OpenAttr<Self, types::MQOO>,
{
Self::open_as(connection, open_option)
}
pub(super) fn open_as<'oo, R>(
connection: C,
open_option: &impl option::OpenOption<'oo, types::MQOO>,
) -> ResultCompErr<R, <R as option::OpenValue<Self>>::Error>
where
R: option::OpenValue<Self>,
{
let mut oo = option::OpenParamOption {
mqod: structs::MQOD::new(default::MQOD_DEFAULT),
options: constants::MQOO_BIND_AS_Q_DEF,
};
open_option.apply_param(&mut oo);
assert!(oo.mqod.Version <= libmqm_sys::MQOD_CURRENT_VERSION);
R::open_consume(&mut oo, |option::OpenParamOption { mqod, options }| unsafe {
let as_connection = connection.as_connection();
as_connection
.mq
.mqopen(as_connection.handle, mqod, *options)
.map_completion(|handle| Self {
handle,
connection,
drop_close_options: constants::MQCO_NONE,
})
})
}
}