Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Implement #[bitcode(with = LocalType)] RemoteType

Abierto
#115 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Tranquilo
Stack tecnológico
rust
Área
backend

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:

  1. serde::Serialize::serialize can return errors, but bitcode::encode can't, we would have to panic.
  2. serde::Deserialize::deserialize can return errors, but luckily bitcode::decode can as well. Unfortunately, we would have to implement infrastructure for dropping T's owned by bitcode::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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de SoftbearStudios/bitcode

Todos los issues de SoftbearStudios/bitcode

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.