spdict 0.1.0

Simple linked list to be used as Dict with xml parser
Documentation
use std::{ffi::c_char, ptr::null_mut};

/// C ABI compatiable struct for storing data
#[repr(C)]
pub struct SPDict {
    /// name
    pub name: *const c_char,
    /// value
    pub value: *const c_char,
    /// ptr to the next obj
    pub next: *mut SPDict,
    /// ptr to the prev obj
    pub prev: *mut SPDict,
}

#[no_mangle]
/// adding new Node to the Dict
pub extern "C" fn spdict_add(
    head: *mut *mut SPDict,
    name: *const c_char,
    value: *const c_char,
) {
    unsafe {
        if (*head).is_null() {
            let new_node = Box::into_raw(Box::new(SPDict {
                name,
                value,
                prev: null_mut(),
                next: null_mut(),
            }));
            *head = new_node;
            return;
        }

        let mut current = *(head);
        while !(*current).next.is_null() {
            current = (*current).next;
        }

        let new_node = Box::into_raw(Box::new(SPDict {
            name,
            value,
            prev: current,
            next: null_mut(),
        }));

        (*current).next = new_node;
    }
}

#[no_mangle]
/// removing whole Dict
pub extern "C" fn spdict_del(head: *mut SPDict) {
    unsafe {
        if !(*head).prev.is_null() {
            let mut tmp_prev = (*head).prev;

            while !(*tmp_prev).prev.is_null() {
                let tmp = tmp_prev;
                tmp_prev = (*tmp).prev;
                let _ = Box::from_raw(tmp);
            }
            let _ = Box::from_raw(tmp_prev);
        }

        let mut tmp_next = head;
        while !(*tmp_next).next.is_null() {
            let tmp = tmp_next;
            tmp_next = (*tmp).next;
            let _ = Box::from_raw(tmp);
        }
        let _ = Box::from_raw(tmp_next);
    }
}