Meta framework. Support for dynamic plug-ins and AOP

Overview

Kokoro

docs.rs Crates.io Version Crates.io License

Dynamic publish-subscribe pattern framework.

Support for dynamic plug-ins and AOP

Not yet stable, do not use in production !!


下面的内容有些老旧了,但是 example 都是正确的

如果你懂得中文,并且想要了解这个仓库到底是什么东西,请查看以下 Markdown

关于 Kokoro-core

关于发布-订阅模式

Simple publish/subscribe

use std::fmt::Display;
use kokoro::prelude::*;
fn main() {
    let ctx = channel_ctx();
    // Register a subscriber
    ctx.subscribe(sub_print);
    // Create a publisher
    let _ = ctx.spawn(|ctx, s| {
        // s is a signal that is true when the thread should be terminated
        while !s.is() {
            // Publish the event:Print
            ctx.publish(Print(&"Hello World"));
            std::thread::sleep(std::time::Duration::from_secs(1));
        }
    });
    ctx.run();
    /* Typically, the output will be :
     *  Hello World
     *  ...
    */
}

#[derive(Event)]
// This is a event:Print
struct Print(&'static dyn Display);

// This is a subscriber who subscribes to the event:Print
fn sub_print(print: &Print) {
    println!("{}", print.0);
}

Plug-in system with dynamic capabilities

APP

use kokoro::prelude::*;

fn main() -> Result<()> {
    let ctx = channel_ctx();
    // let dyp = DynamicPlugin::from_path("path to Plugin (Dynamic link library)"); // Also can do it
    // let dyp = DynamicPlugin::try_from(unsafe { libloading::Library::new("path to Plugin (Dynamic link library)") }); // Also can do it
    let dyp = "path to Plugin (Dynamic link library)"; // String or Library or DynamicPlugin
    let config = toml::toml! {
        hello = "I am plugin"
    };
    ctx.plugin_dynamic(dyp, Some(content.into()))?;
    ctx.publish(PhantomEvent);
    ctx.run();
    /* Typically, the output will be :
     *  I am plugin plugin-example
    */
    Ok(())
}

Plugin (Dynamic link library)

use kokoro::prelude::*;
use kokoro::dynamic_plugin::toml::Value;
use serde::Deserialize;

#[derive(DynamicPlugin, Deserialize)]
struct MyPlugin {
    hello: String,
}

impl Plugin for MyPlugin {
    type MODE = MPSC;
    const NAME: &'static str = "plugin-example";
    fn apply(ctx: Context<Self, MPSC>) -> Result<()> {
        ctx.subscribe(sub);
        Ok(())
    }
}

impl Create for MyPlugin {
    fn create(config: Option<Value>) -> Result<Self> {
        if let Some(config) = config {
            let config = MyPlugin::deserialize(config)?;
            Ok(config)
        } else {
            Err(anyhow!("Required Config"))
        }
    }
}

fn sub(ctx: &Context<MyPlugin, MPSC>) {
    println!(
        "{} {}",
        ctx.hello,
        MyPlugin::NAME
    );
}

Star History

Star History Chart

todo list

  • kokoro-default-impl
    • kokoro-plugin-impl
    • kokoro-thread-impl
    • kokoro-service-impl (AOP Support)
  • kokoro-dynamic-plugin-impl
  • plugin config api
  • loader for dynamically and schematically loading plugins.
  • logger for uniform output logging of plugins.
  • k-onfig is used to hint configuration schema.
  • Satori (EventType only) for instant messaging or chatbots
You might also like...
Inspect dynamic dependencies of Mach-O binaries recursively

dylibtree dylibtree is a tool for inspecting the dynamic dependencies of a Mach-O binary recursively. It can be useful to understand what library load

Dynamic, Type-Erased Key-Value Maps in Rust

Dynamic Objects in Rust Do you love Rust but are tired of being constrained by static typing when you need a map to hold values of different types? Do

🖥  A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3
🖥 A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3

🖥 A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3

Detects whether a terminal supports color, and gives details about that support

Detects whether a terminal supports color, and gives details about that support. It takes into account the NO_COLOR environment variable. This crate i

A minimal readline with multiline and async support
A minimal readline with multiline and async support

RustyLine Async A minimal readline with multiline and async support. Inspired by rustyline , async-readline & termion-async-input.

🏭 Convert Markdown documents into themed HTML pages with support for code syntax highlighting, LaTeX and Mermaid diagrams.
🏭 Convert Markdown documents into themed HTML pages with support for code syntax highlighting, LaTeX and Mermaid diagrams.

Marky Markdown Magician 🧙 Features Hot reload previewing 🔥 Conversion to HTML / PDF 🏭 Themes! ✨ Extensions - Math, diagrams, syntax-highlighting 🧩

Holo is a suite of routing protocols designed to support high-scale and automation-driven networks.

Holo is a suite of routing protocols designed to support high-scale and automation-driven networks. For a description of what a routing protocol is, p

Use Thunk to build your Rust program that runs on old Windows platforms, support Windows XP and more!

Use Thunk to build your Rust program that runs on old platforms. Thunk uses VC-LTL5 and YY-Thunks to build programs that support old platforms. So, ho

LaTeX support for Typst, powered by Rust and WASM.
LaTeX support for Typst, powered by Rust and WASM.

MiTeX LaTeX support for Typst, powered by Rust and WASM. MiTeX processes LaTeX code into an abstract syntax tree (AST). Then it transforms the AST int

Releases(v0.0.6-alpha)
  • v0.0.6-alpha(Feb 28, 2024)

    docs.rs Crates.io Version


    您好 🥳🎉🎉

    这里是 Kokoro,我们发布了 v0.0.6-alpha。

    更改:

    1. 修复了一些不为人知的 bug,作者休息了一段时间,看了很多漫画。
    2. kokoro-flume-channle: mpsc_context() -> channel_ctx()
    3. kokoro-flume-channle: MPSC<R> -> MPSC<R = ()>
    4. kokoro-dynamic-plugin: 新增了工具 PluginFinder,主要用于跨平台加载插件。
    5. kokoro-defualt-impl: plugin: unplugin() -> unplug()
    6. kokoro-dynamic-plugin: plugin_dynamic() 现在支持多种方式加载插件。
    7. kokoro-dynamic-plugin: 将 Library 进行了包装,新增 DynamicPlugin

    PluginFinder

    let pf = PluginFinder::new("./plugins"); // 保存插件动态链接库的目录
    let pe = pf.find("plugin_example"); // 在目录下寻找插件 plugin_example
    println!("{pe}") // 得到的是插件的路径
    ctx.plugin_dynamic(pe, Some(config)); // 可以通过路径直接加载,同样也可以通过 Library 直接加载。
    

    关于

    此次更新主要是提高用户体验。其余更新内容,请通过 example 了解。

    下次更新将会有大变动,故提前发布 0.0.6。

    todo

    • [x] kokoro-default-impl
      • [x] kokoro-plugin-impl
      • [x] kokoro-thread-impl
      • [x] kokoro-service-impl (AOP Support)
    • [x] kokoro-dynamic-plugin-impl
    • [x] plugin config api
    • [ ] loader for dynamically and schematically loading plugins.
    • [ ] logger for uniform output logging of plugins.
    • [x] k-onfig is used to hint configuration schema.
    • [ ] Satori (EventType only) for instant messaging or chatbots
    Source code(tar.gz)
    Source code(zip)
  • v0.0.5-alpha(Feb 22, 2024)

    docs.rs Crates.io Version


    Hello World 🥳🎉🎉

    This is the Kokoro team, we released v0.0.5-alpha,

    Kokoro-core is tentatively available, so you can try out plugins.

    You can try to build some places to apply it, to verify its feasibility.

    您好 🥳🎉🎉

    这里是 Kokoro,我们发布了 v0.0.5-alpha,

    这时的 Kokoro-core 已经初步可用,请大家尝试开发插件。

    并在某些地方尝试应用它,来验证它的可行性。

    todo

    • [x] kokoro-default-impl
      • [x] kokoro-plugin-impl
      • [x] kokoro-thread-impl
      • [x] kokoro-service-impl (AOP Support)
    • [x] kokoro-dynamic-plugin-impl
    • [x] plugin config api
    • [ ] loader for dynamically and schematically loading plugins.
    • [ ] logger for uniform output logging of plugins.
    • [ ] k-onfig is used to hint configuration schema.
    • [ ] Satori (EventType only) for instant messaging or chatbots
    Source code(tar.gz)
    Source code(zip)
Owner
Kokoro
Kokoro
🐱 HQ9C is a very serioues compiler for HQ9+, it meta-compiles with Rust.

HQ9+ Compiler HQ9c (Or HQ9+ Compiler) is a blockchain-based NFT minting AI machine-learning cloud infraestructure for the compiling of the great progr

Alex 5 Aug 28, 2022
🚧 Meta Programming language automating multilang communications in a smart way

Table of Contents Merge TLDR Manifest merge-lang Inference File Structure Compile Scheduling Execution Runtime Package Manager API Merge NOTE: Any of

camel_case 4 Oct 17, 2023
A versatile and dynamic music bot designed to elevate the musical experience within Discord servers.

Masayoshi Masayoshi is a discord music bot written in Rust for making a great experience within Discord servers with support to Youtube, SoundCloud, S

null 6 Dec 26, 2023
A universal load testing framework for Rust, with real-time tui support.

rlt A Rust Load Testing framework with real-time tui support. rlt provides a simple way to create load test tools in Rust. It is designed to be a univ

Wenxuan 129 Jul 20, 2024
An embeddable dynamic programming language for Rust.

rune Visit the site ?? - Read the book ?? An embeddable dynamic programming language for Rust. Contributing If you want to help out, there should be a

The Rune Programming Language 1.1k Dec 27, 2022
Like a cell, but make lifetimes dynamic instead of ownership

LendingCell is a mutable container that allows you to get an owned reference to the same object. When the owned reference is dropped, ownership return

Kalle Samuels 19 Dec 15, 2022
Apple dynamic HEIF wallpapers on GNU/Linux.

timewall Apple dynamic HEIF wallpapers on GNU/Linux. Features: Support for original HEIF/HEIC dynamic wallpaper files used in MacOS. Support for all s

Bazyli Cyran 15 Dec 15, 2022
Dynamic dependency injection library for rust.

DDI (dynamic dependency injection) This library provides a generic dependency injection container that can be easily integrated into any application a

EYHN 34 Feb 21, 2023
AI-powered game engine for dynamic, personalized experiences in evolving worlds. Ethical, accessible, inclusive.

ARCADIA: Advanced and Responsive Computational Architecture for Dynamic Interactive Ai: A Whitepaper By Reuven Cohen (rUv) Introduction Imagine a futu

rUv 10 Apr 18, 2023