pub struct SessionInfo<'a> {
pub channelnum: u8,
pub hostserial: u32,
pub callerid_len: u8,
pub callerid: &'a str,
}
pub fn get_session<'a>(
channel_num: u8,
host_serial: u32,
caller_id: &'a str,
) -> Result<SessionInfo<'a>, Box<dyn std::error::Error>> {
let callerid_len = 13u8;
if !(1..=50).contains(&channel_num) {
return Err(Box::new(ChannelOutOfRange));
}
Ok(SessionInfo {
channelnum: channel_num,
hostserial: host_serial,
callerid_len,
callerid: caller_id,
})
}
#[derive(Debug, Clone)]
struct ChannelOutOfRange;
impl std::fmt::Display for ChannelOutOfRange {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "The channel must be between 1 and 50.")
}
}
impl std::error::Error for ChannelOutOfRange {}