Coder Social home page Coder Social logo

misery-rs's Introduction

misery-rs โ€ƒ misery: rustc 1.60+

- About library naming...
In creating my first "proper" working library, I feel like "misery" that I wanted to write better...

Usage

[dependencies]
misery-rs = { git = "https://github.com/ReiRokusanami0010/misery-rs" }
use serde::{Serialize, Deserialize};

async fn asynchronous_handling() {
    {
        /// External files generated for caching are generated (or saved) at the time of Drop.
        /// Note: this process uses blocking and is a synchronous process.
        let caching: MiseryHandler<StringId<Article>, Article> = MiseryHandler::load_from_blocking("./test/article_cache.json");

        let vec = vec![
            CacheWrapper::new(StringId::<Article>::new("abc"), Article::new("abc", "test_1", 123)),
            CacheWrapper::new(StringId::<Article>::new("def"), Article::new("def", "test_2", 456)),
            CacheWrapper::new(StringId::<Article>::new("ghi"), Article::new("ghi", "test_3", 789)),
            CacheWrapper::new(StringId::<Article>::new("jkm"), Article::new("jkm", "test_4", 321)),
            CacheWrapper::new(StringId::<Article>::new("nop"), Article::new("nop", "test_5", 654)),
        ];

        for item in vec {
            let caching = &caching;
            caching.push(item).await;
        }
    }
    assert!(std::path::Path::new("./test/usage_test.json").exists());
}

/// `Clone`, `Hash`, `Eq`, `PartialEq`, and `PartialEq` required by misery-rs for caching.
/// Also, `serde::Serialize` and `serde::deserialize` must be implemented.
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
pub struct StringId<T> {
    id: String,
    #[serde(skip)]
    _mark: std::marker::PhantomData<T>
}

impl<T> StringId<T> {
    fn new<I>(id: I) -> StringId<T> where I: Into<String> {
        Self { id: id.into(), _mark: std::marker::PhantomData }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
pub struct Article {
    id: StringId<Article>,
    title: String,
    page: i32
}

impl Article {
    fn new<I, S>(id: I, title: S, page: i32) -> Article
        where I: Into<String>, S: Into<String> 
    {
        Self { 
            id: StringId::<Self>::new(id),
            title: title.into(),
            page
        }
    }
}

misery-rs's People

Contributors

halsekiraika avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.