libikarus 0.1.14

The core functionality of Ikarus wrapped neatly in a rust library
Documentation
use crate::objects::folder::{folder_get_children_count, Folder, FolderHelperError, FolderOrScope};
use crate::objects::object::ObjectScope;
use sqrite::connection::Connection;
use std::rc::Rc;
use tracing::*;

#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
pub enum FolderPosition {
    StartOfFolder,
    At(usize),
    EndOfFolder,
}

impl std::fmt::Display for FolderPosition {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{:?}", self)
    }
}

impl FolderPosition {
    #[instrument(level = Level::DEBUG, skip(conn))]
    pub fn resolve(
        &self,
        conn: Rc<Connection>,
        scope: ObjectScope,
        folder: Option<Folder>,
    ) -> Result<usize, FolderHelperError> {
        Ok(match self {
            FolderPosition::StartOfFolder => 0,
            FolderPosition::At(pos) => *pos,
            FolderPosition::EndOfFolder => folder_get_children_count(
                conn.clone(),
                FolderOrScope::from_opt_folder(folder, scope),
            )?,
        })
    }
}

#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct Location<F: std::fmt::Debug> {
    pub parent: Option<F>,
    pub position: usize,
}

impl<F: std::fmt::Debug> std::fmt::Display for Location<F> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{:?}", self)
    }
}