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

Getting the path of a Dir

Abierto
#373 4 comentarios 0 reacciones 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
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
rust

Línea de trabajo

Comienza revisando las APIs Dir existentes de cap-std y los métodos ProjectDirs de cap-directories; después, examina cómo el wrapper propuesto realiza el seguimiento de las rutas. La tarea estaría terminada cuando haya una API acordada y advertencias documentadas sobre el modelo de capacidades; el issue no indica archivos ni tests que actualizar.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Sometimes I'd like to be able to get the path for a Dir.

For example,

  • logs or debugging
  • passing the path to a separate process
  • passing the path to a library that doesn't yet support the capability model

For example, in a personal project, I'm using the git2 wrapper around libgit2. In order to call Repository::clone(url, path), I need the path of the cache directory. I could use gitoxide, a pure rust implementation of git, however that would have the same problem. Maybe in the future we can make gitoxide use cap-std, but for now that's not an option.

Yes, some of these examples break the capability model, however, from a pragmatic point of view, that may be acceptable.

I'm not sure what the best approach here is, but in my personal project I'm using a wrapper like

pub struct DirWithPath {
    dir: Dir,
    path: PathBuf,
}

with a constructor like

pub fn open_ambient_dir<P: AsRef<Path>>(path: P, ambient_authority: AmbientAuthority) -> io::Result<Self> {
    Dir::open_ambient_dir(path.as_ref(), ambient_authority).map(|dir| Self {
        dir,
        path: path.as_ref().to_path_buf(),
    })
}

and an open_dir method that concatenates the path:

pub fn open_dir<P: AsRef<Path>>(self: &Self, path: P) -> io::Result<Self> { 
    let full_path = self.path.join(path.as_ref());
    self.dir.open_dir(path).map(|dir| Self {                                                                                                                                     
        dir,
        path: full_path,
    })
}

One issue with maintaining my own wrapper is that I can't use e.g ProjectDirs from cap-directories because its methods return Dirs, so the paths are unknown. I would have to wrap directories_next directly.

I wonder if it would be useful for other people if something like this was added to cap-std (with appropriate warnings with respect to it breaking the capability model)?

Lenguaje dominante
Rust
Estrellas
821
Forks
59
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

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 bytecodealliance/cap-std

Todos los issues de bytecodealliance/cap-std

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.