pub struct Project { /* private fields */ }Expand description
A project loaded entirely in memory as PureFile ASTs.
This is a pure data container with I/O capabilities.
For transformations, use ryo-executor::Workspace.
For searching, use ryo-analysis::DiscoveryEngine.
§Fields
config_root: Location ofryo.toml(or where it would be)metadata: Cargo workspace metadata (crate info, paths)config: Project configuration fromryo.tomlfiles: Loaded source files
Implementations§
Source§impl Project
impl Project
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Self, ProjectError>
pub fn load(path: impl AsRef<Path>) -> Result<Self, ProjectError>
Load a project from disk
§Workflow
- Look for
ryo.tomlin the given directory - Determine Cargo.toml location from config or auto-detect
- Create
CargoMetadataProviderfor workspace info - Load files by traversing mod declarations from entry points
§Arguments
path- Directory containing the project (with or without ryo.toml)
Sourcepub fn config_root(&self) -> &Path
pub fn config_root(&self) -> &Path
Get the config root (where ryo.toml is or would be)
Sourcepub fn workspace_root(&self) -> &Path
pub fn workspace_root(&self) -> &Path
Get the workspace root (from Cargo metadata)
Sourcepub fn root(&self) -> &Path
pub fn root(&self) -> &Path
Get the root path (alias for workspace_root for backward compatibility)
Sourcepub fn metadata(&self) -> &CargoMetadataProvider
pub fn metadata(&self) -> &CargoMetadataProvider
Get the Cargo metadata provider
Sourcepub fn path_resolver(&self) -> WorkspacePathResolver
pub fn path_resolver(&self) -> WorkspacePathResolver
Create a WorkspacePathResolver for this project
Uses workspace type from CargoMetadataProvider to correctly validate
crate:: paths (ambiguous in multi-crate workspaces).
Sourcepub fn file_paths(&self) -> impl Iterator<Item = &PathBuf>
pub fn file_paths(&self) -> impl Iterator<Item = &PathBuf>
Get all file paths
Sourcepub fn file_count(&self) -> usize
pub fn file_count(&self) -> usize
Number of files loaded
Sourcepub fn resolve_path(&self, path: &Path) -> Option<PathBuf>
pub fn resolve_path(&self, path: &Path) -> Option<PathBuf>
Resolve a path to the actual key in the files HashMap. Handles both relative and absolute paths.
Sourcepub fn get_file_mut(&mut self, path: &Path) -> Option<&mut PureFile>
pub fn get_file_mut(&mut self, path: &Path) -> Option<&mut PureFile>
Get a mutable file by path
Sourcepub fn insert_file(&mut self, path: PathBuf, file: PureFile)
pub fn insert_file(&mut self, path: PathBuf, file: PureFile)
Insert or update a file
Sourcepub fn get_file_with_path(&self, path: &Path) -> Option<(PathBuf, &PureFile)>
pub fn get_file_with_path(&self, path: &Path) -> Option<(PathBuf, &PureFile)>
Get a file and its resolved path
Sourcepub fn get_file_mut_with_path(
&mut self,
path: &Path,
) -> Option<(PathBuf, &mut PureFile)>
pub fn get_file_mut_with_path( &mut self, path: &Path, ) -> Option<(PathBuf, &mut PureFile)>
Get a mutable file and its resolved path
Sourcepub fn contains_file(&self, path: &Path) -> bool
pub fn contains_file(&self, path: &Path) -> bool
Check if a file exists
Sourcepub fn get_source(&self, path: &Path) -> Result<Option<String>, ProjectError>
pub fn get_source(&self, path: &Path) -> Result<Option<String>, ProjectError>
Get generated source for a file
Sourcepub fn write_to_disk(&self, paths: &[PathBuf]) -> Result<usize, ProjectError>
pub fn write_to_disk(&self, paths: &[PathBuf]) -> Result<usize, ProjectError>
Write modified files back to disk
Creates parent directories if they don’t exist (for newly created files).
Sourcepub fn write_all_to_disk(&self) -> Result<usize, ProjectError>
pub fn write_all_to_disk(&self) -> Result<usize, ProjectError>
Write all files to disk
Sourcepub fn load_files(
root: impl AsRef<Path>,
) -> Result<HashMap<PathBuf, PureFile>, ProjectError>
pub fn load_files( root: impl AsRef<Path>, ) -> Result<HashMap<PathBuf, PureFile>, ProjectError>
Load files from a project directory without creating a Project instance.
This is the preferred method for the Context-centric design where
AnalysisContext is the Single Source of Truth for file content.
§Example
let files = Project::load_files("/path/to/project")?;
let context = AnalysisContext::from_path_files(files, "crate");Sourcepub fn write_from_context(
&self,
ctx: &AnalysisContext,
files: &[WorkspaceFilePath],
) -> Result<usize, ProjectError>
pub fn write_from_context( &self, ctx: &AnalysisContext, files: &[WorkspaceFilePath], ) -> Result<usize, ProjectError>
Sourcepub fn sync_from_context(
&mut self,
ctx: &AnalysisContext,
files: &[WorkspaceFilePath],
)
pub fn sync_from_context( &mut self, ctx: &AnalysisContext, files: &[WorkspaceFilePath], )
Sync modified files from Context back to Project.files.
Maintains backward compatibility for code that still reads from Project.files.
Auto Trait Implementations§
impl Freeze for Project
impl RefUnwindSafe for Project
impl Send for Project
impl Sync for Project
impl Unpin for Project
impl UnsafeUnpin for Project
impl UnwindSafe for Project
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more