rs-bag 0.1.0

Read, write and modify ROS 2 rosbag2 sqlite3 (.db3) storage files
Documentation
use turso::Row;

use crate::Error;
use crate::error::Result;

#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Topic {
    pub id: i64,
    pub name: String,
    #[serde(rename = "type")]
    pub r#type: String,
    pub serialization_format: String,
    pub offered_qos_profiles: String,
}

impl PartialEq for Topic {
    fn eq(&self, other: &Topic) -> bool {
        self.id == other.id
    }
}

impl Eq for Topic {}

impl std::hash::Hash for Topic {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.id.hash(state);
    }
}

impl TryFrom<Row> for Topic {
    type Error = Error;

    fn try_from(value: Row) -> Result<Self> {
        let id = value
            .get_value(0)?
            .as_integer()
            .copied()
            .ok_or(Error::row_conversion("id", "an integer"))?;

        let name = value
            .get_value(1)?
            .as_text()
            .cloned()
            .ok_or(Error::row_conversion("name", "text"))?;

        let r#type = value
            .get_value(2)?
            .as_text()
            .cloned()
            .ok_or(Error::row_conversion("type", "text"))?;

        let serialization_format = value
            .get_value(3)?
            .as_text()
            .cloned()
            .ok_or(Error::row_conversion("serialization_format", "text"))?;

        let offered_qos_profiles = value
            .get_value(4)?
            .as_text()
            .cloned()
            .ok_or(Error::row_conversion("offered_qos_profiles", "text"))?;

        Ok(Self {
            id,
            name,
            r#type,
            serialization_format,
            offered_qos_profiles,
        })
    }
}