Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Get part result from default()

Aperta
#85 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
cli, tooling

Direzione di ricerca

Start with the reproducer in testconfig.rs and main.rs, especially the blank test.toml and the confy::load_path:: call. Verify the loaded value and compare it with the Default implementations; done should mean the expected behavior for an empty file is clearly established and covered by a focused test or documentation.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Result is None when test.toml is blank. I wish to get as below, how can I do it?

Some(
    Test {
        sub: Some(
            [
                Data {
                    id: 2,
                    name: "3",
                },
                Data {
                    id: 4,
                    name: "5",
                },
            ],
        ),
    },
)

my code is here:

testconfig.rs:

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct Data {
    pub id: usize,
    pub name: String,
}
impl Default for Data {
    fn default() -> Self {
        Self {
            id: 1,
            name: "test1".to_string(),
        }
    }
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Test {
    #[allow(dead_code)]
    pub sub: Option<Vec<Data>>,
}
impl Default for Test {
    fn default() -> Self {
        Self { sub: Some(vec![Data{id:2,name: "3".to_string()}, Data{id:4, name: "5".to_string()}]) }
    }
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TestGlobalConfig {
    #[allow(dead_code)]
    pub test: Option<Test>,
}
impl Default for TestGlobalConfig {
    fn default() -> Self {
        Self { test: Some(Test::default()) }
    }
}

main.rs:

use std::sync::RwLock;
pub mod testconfig;
use crate::testconfig::TestGlobalConfig;
lazy_static::lazy_static! {
    static ref GLOBAL: RwLock<TestGlobalConfig> ={
        let path = concat!(env!("CARGO_MANIFEST_DIR"),"/test.toml");
        if let Ok(global_config) = confy::load_path::<TestGlobalConfig>(path) { 
            RwLock::new(global_config)
        } else {
            panic!("load config file {path:?} error!");
        }
    };
}
fn main() {
    let binding = GLOBAL.read().unwrap();
    let settings = &binding.test;
    println!("{:#?}", settings);
}
Lingua principale
Rust
Stelle
1k
Fork
80
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-cli/confy

Tutte le issue di rust-cli/confy

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.