Implement #[bitcode(with = LocalType)] RemoteType
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza revisando el issue #47, las APIs públicas bitcode::Encode y bitcode::Decode, y el comportamiento de serde::Serialize y serde::Deserialize descrito aquí. Se considera terminado cuando se admitan #[bitcode(with = ...)] y tipos separados encode_with/decode_with sin depender de un manejo de errores basado en panic ni de un manejo inseguro de la vida útil del decodificador.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
#47 has not yet been implemented due to complexity surrounding:
serde::Serialize::serializecan return errors, butbitcode::encodecan't, we would have to panic.serde::Deserialize::deserializecan return errors, but luckilybitcode::decodecan as well. Unfortunately, we would have to implement infrastructure for dropping T's owned bybitcode::Decoders while keeping the decoders themselves alive. Keeping unsafe code involving drop panic-safe is a non-trivial task.
Therefore, a simpler alternative to get most bitcode users unstuck would be something like
use bespoke_string::CompactZeroCopyArcStr;
#[derive(bitcode::Encode, bitcode::Decode)]
struct User {
#[bitcode(with = LocalString)]
first_name: CompactZeroCopyArcStr,
// If you wanted a different encoder and decoder type (e.g. non &str types cannot borrow during decode).
#[bitcode(encode_with = LocalString, decode_with = LocalString)]
last_name: CompactZeroCopyArcStr,
}
#[derive(bitcode::Encode, bitcode::Decode)]
struct LocalString<'a>(&'a str);
impl<'a> From<&'a CompactZeroCopyArcStr> for LocalString<'a> {
fn from(v: &'a CompactZeroCopyArcStr) -> Self {
Self(v.as_str())
}
}
impl From<LocalString<'_>> for CompactZeroCopyArcStr {
fn from(v: LocalString) -> Self {
Self::new(v.0)
}
}
See also:
https://github.com/SoftbearStudios/bitcode/issues/13
https://docs.rs/serde_with
https://rkyv.org/derive-macro-features/remote-derive.html
To avoid the complexity present with #47, you would not be able to return errors during decoding.
If such an error did occur, you would have to construct a zero value of the type. Some examples:
- Time outside range, return the zero time
- FiniteVec has too many elements, return an empty vec
- OsString/CString has invalid characters, return an empty string
If for some reason you needed to know if an error occurred (not just handling decoding untrusted bytes from the network), you could store the error out of band in a thread_local and check for errors after decode.
Important: Panicking during decode and using catch_unwind is not a valid implementation of error handling. Bitcode relies on in place initialization during decode for performance, so any panics during decode result in leaked memory.
Currently the only way to observe this with the public API is to panic in PartialEq, Ord, or Hash inside the HashMap and BTreeMap decoders.
Because this feature would present a larger surface for accidently leaking memory, it's probably best for bitcode to catch_unwind (in at least debug mode) and cause the process to abort with an error message explaining the issue.
- Lenguaje dominante
- Rust
- Estrellas
- 671
- Forks
- 61
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de SoftbearStudios/bitcode
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
SoftbearStudios/bitcode#122 · 1 reacción ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
SoftbearStudios/bitcode#121 · 2 comentarios ·
-
Support for `nonmax` crate.Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
SoftbearStudios/bitcode#110 · 1 reacción ·
-
BUffer for serde?Quizá libre de nuevo @caibear la tomó hace 222 días y no hay ningún pull request abierto. Abierto
SoftbearStudios/bitcode#102 · 1 comentario · 1 asignado ·
-
question
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
SoftbearStudios/bitcode#91 · 5 comentarios ·
Todos los issues de SoftbearStudios/bitcode
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
stellar/stellar-cli#2773 ·
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
voidzero-dev/oxc-angular-compiler#511 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 86/100
yantrikos/yantrik-os#539 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
documentation station:mac ui-dashboard
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
rolter-ai/rolter#2490 · 1 comentario ·
Los mantenedores suelen responder en 1 día