Feature request: enabling grammar typing for sequences via deserialize
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Start by reading the deserializer’s sequence handling, especially SeqItemDeserializer::deserialize_seq, and compare it with the serializer’s flattening behavior. The issue describes two changes: trying None for remaining tuple elements at sequence end and recursively flattening nested sequences; investigate the infinite-loop risk for vectors of Option and other design effects before proposing an approach. Done means the example round-trips while sequence termination and nested sequences behave safely.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
This issue is to gauge interest in being able to validate the variadic layout of a sequence via tuple elements that are Option
I have a use case to generate schema definitions with sequences defined by a grammar. Given that it's already possible to enforce order, and serializing has builtin flattening of options and sequences, there are two key features for deserializing missing that would fully enable building types to validate a sequence grammar.
Deserializing end of sequence for a tuple should try to deserialize as visiting None for each remaining element of the tuple sequence.
Deserializing a sequence of sequences (of sequences...*) should recursively flatten.
Both these features are already present implicitly in the serializer, this would just be making the deserializer match.
This would allow for examples like below to work
use quick_xml::{de::from_str, se::to_string};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
enum ABChoice {
A,
B,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
enum CDChoice {
C,
D,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
struct Root {
#[serde(rename = "$value")]
content: (Vec<ABChoice>, Vec<CDChoice>, Option<Vec<ABChoice>>),
}
let root = Root {
content: (
vec![ABChoice::A, ABChoice::B],
vec![CDChoice::C],
Some(vec![ABChoice::A]),
),
};
let serialized = to_string(&root).unwrap();
dbg!(&serialized);
let deserialized = from_str(&serialized).unwrap();
assert_eq!(root, deserialized);
Currently serializing this produces the string
<Root><A/><B/><C/><A/></Root>
Mirroring this in the deserializer is desirable.
I've managed to get a hacky implementation of this to work sending all cases that would stop iteration to first try and deserialize as the DeserializeSeed with a deserializer that can only call visit_none, however this would lead to the case where a vector of Options produces an infinite loop so there's still some design work to be done there.
With regards to recursive sequence flattening, I suspect the offender is <SeqItemDeserializer as de::Deserializer>::deserialize_seq, however just making this recursive seems to have other potential ramifications associated. As such, design input would be appreciated there as well.
I'm very happy to do the work myself. However, I would like to consult, firstly, if this would be something that can be upstreamed, and secondly if there are any pitfalls in this area I should be aware of from a design standpoint, particularly that would prevent it getting upstreamed.
- Lingua principale
- Rust
- Stelle
- 1.6k
- Fork
- 299
- Merge medio
- 2g 4h
- PR unite (30g)
- 9
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tafia/quick-xml
-
Parser accepts an empty element or attribute nameForse già presa @ychampion l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
DecodingReader::set_encoding panics when the XML declaration is longer than 64 bytesForse già presa @emschwartz l’ha presa 4 giorni fa. Apertabug encoding
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
tafia/quick-xml#1040 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
encoding optimization
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
tafia/quick-xml#1039 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
optimization question
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 4/5 1-2 giorni Idoneità per principianti 53/100
tafia/quick-xml#1035 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di tafia/quick-xml
Issue simili
-
[Bug]: opencode_go chat route drops reasoning_effort (even 'none'), while the same endpoint honors it via custom_llm_provider=openaiForse già presa @arvindkumar-ship-it l’ha presa oggi. Apertallm translation
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
BerriAI/litellm#51871 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
comp-formats
Difficoltà 2/5 Mezza giornata Idoneità per principianti 64/100
ClickHouse/ClickHouse#131694 ·
I maintainer di solito rispondono entro 1 giorno
-
cli: `execCargoMetadata` decodes stdout per chunk, corrupting non-ASCII paths across pipe boundariesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
C-Bug S-Needs-Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
bevyengine/bevy#26558 ·
I maintainer di solito rispondono entro 2 giorni