[Rust Daily] 2023-09-24 標準ライブラリに cfg_match! を追加しました

cfg_match! が標準ライブラリに追加されました

#![feature(cfg_match)]

cfg_match! {
    cfg(unix) => {
        fn foo() { /* unix specific functionality */ }
    }
    cfg(target_pointer_width = "32") => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}

GitHub: https://github.com/rust-lang/rust/pull/115416

viewbuilder クロスプラットフォーム UI フレームワーク

このクレートは、UI バックエンドに HTML のようなレンダリング API を提供します。これは特に concoct のバックエンドとして構築されていますが、独自の状態管理ツールを導入したり、独自のフレームワークを構築したりするためのバックエンドとして使用することもできます。

特徴は次のとおりです。

  • クロスプラットフォームで、デスクトップとモバイルデバイスをサポートします。
  • HTML に似たイベント処理 API を備えています。
  • taffy を使用して実装された CSS フレキシブル ボックスとグリッド レイアウト。
  • accesskit を通じてアクセシビリティ サポートを実装します。
  • Rust-skiaを使用した高性能レンダリング。

使用例:

let mut tree = Tree::default();
let root = Element::new()
    .align_items(AlignItems::Center)
    .justify_content(JustifyContent::Center)
    .child(tree.insert("Hello World!"))
    .build(&mut tree);

viewbuilder::run(tree, root)

GitHub: https://github.com/concoct-rs/viewbuilder

fancy-duration v0.6.0 がリリースされました

fancy-duration は Go の time.ParseDuration に似たスキームを実装し、秒とナノ秒を使用できる任意の型に適した一般的な期間を生成します。デフォルトでserde、time、chronoクレートをサポートしており、独自のデュレーションをserdeなどと互換性を持たせるために実装できる機能を提供します。コンパクトでスペース区切りの形式を提供します。

使用例:

use std::time::Duration;
use fancy_duration::FancyDuration;

pub fn main() {
    assert_eq!(FancyDuration(Duration::new(20, 0)).to_string(), "20s");
    assert_eq!(FancyDuration(Duration::new(600, 0)).to_string(), "10m");
    assert_eq!(FancyDuration(Duration::new(120, 0)).to_string(), "2m");
    assert_eq!(FancyDuration(Duration::new(185, 0)).to_string(), "3m 5s");
    assert_eq!(FancyDuration::<Duration>::parse("3m 5s").unwrap().duration(), Duration::new(185, 0));
    assert_eq!(FancyDuration(Duration::new(185, 0)).to_string(), "3m 5s");

    #[cfg(feature = "time")]
    {
        // also works with time::Duration from the `time` crate
        assert_eq!(FancyDuration(time::Duration::new(20, 0)).to_string(), "20s");
        assert_eq!(FancyDuration(time::Duration::new(600, 0)).to_string(), "10m");
        assert_eq!(FancyDuration(time::Duration::new(120, 0)).to_string(), "2m");
        assert_eq!(FancyDuration(time::Duration::new(185, 0)).to_string(), "3m 5s");
        assert_eq!(FancyDuration::<time::Duration>::parse("3m 5s").unwrap().duration(), time::Duration::new(185, 0));
        assert_eq!(FancyDuration(time::Duration::new(185, 0)).to_string(), "3m 5s");
    }

    #[cfg(feature = "chrono")]
    {
        // also works with chrono!
        assert_eq!(FancyDuration(chrono::Duration::seconds(20)).to_string(), "20s");
        assert_eq!(FancyDuration(chrono::Duration::seconds(600)).to_string(), "10m");
        assert_eq!(FancyDuration(chrono::Duration::seconds(120)).to_string(), "2m");
        assert_eq!(FancyDuration(chrono::Duration::seconds(185)).to_string(), "3m 5s");
        assert_eq!(FancyDuration::<chrono::Duration>::parse("3m 5s").unwrap().duration(), chrono::Duration::seconds(185));
        assert_eq!(FancyDuration(chrono::Duration::seconds(185)).to_string(), "3m 5s");
    }
}

GitHub: https://github.com/erikh/fancy-duration


デイリーチームリーダーの秦より

コミュニティ学習交換プラットフォームのサブスクリプション:

  • Rustcc フォーラム: RSS をサポート
  • WeChat パブリック アカウント: Rust 言語の中国語コミュニティ

おすすめ

転載: blog.csdn.net/u012067469/article/details/133285690