Crates.io | rustsn |
lib.rs | rustsn |
version | 0.26.0 |
source | src |
created_at | 2024-10-11 17:56:22.288442 |
updated_at | 2024-10-21 03:33:05.632076 |
description | This Rust-based tool generates, compiles, and tests code using LLMs, resolves dependencies, and provides explanations of existing code through embeddings. |
homepage | |
repository | https://github.com/evgenyigumnov/rustsn |
max_upload_size | |
id | 1405622 |
size | 234,070 |
language | generate function | generate application | ask |
---|---|---|---|
Rust | + | - | + |
JavaScript | + | - | + |
C# | - | - | + |
Python | + | - | - |
TypeScript | + | - | - |
Java | + | - | - |
Kotlin | + | - | - |
Swift | + | - | - |
PHP | + | - | - |
Scala | + | - | - |
Project name "rustsn" is a combination of "Rust" and "Snippet" words. Code snippets are generated by the tool written in Rust language.
ollama pull qwen2.5-coder:7b
ollama pull bge-large # if your need "ask" command functionality for existed project code
cargo install rustsn
This command will download the package source from crates.io, build it, and install the binary into the standard Cargo binaries directory ($HOME/.cargo/bin on Unix-like systems, or %USERPROFILE%.cargo\bin on Windows). If PATH variable is correctly configured, you can run the tool from any directory.
Start the Program
rustsn generate function --lang=rust
Provide an Explanation
The program will prompt:
Explain what the function should do:
Enter a detailed explanation of the function you want to generate.
parse json string and return struct User (age, name)
Completion
Once the code compiles and all tests pass, the final code and tests will be displayed and result of work will be saved in sandbox
folder.
For example:
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug)]
struct User {
name: String,
age: u32,
}
fn solution(json_string: &str) -> Result<User, serde_json::Error> {
let user: User = serde_json::from_str(json_string)?;
Ok(user)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_solution() {
let json_string = r#"{"name": "John Doe", "age": 30}"#;
let user = solution(json_string).unwrap();
assert_eq!(user.name, "John Doe");
assert_eq!(user.age, 30);
}
#[test]
fn test_solution_invalid_json() {
let json_string = r#"{"name": "John Doe", "age": }"#;
assert!(solution(json_string).is_err());
}
}
Finished
Start the Program
rustsn ask /path/to/your/project --lang=rust
Provide an Explanation
The program will prompt:
Enter the question about your project sources:
Enter a question about your project sources.
How work parse function for PDF files?
Completion
The program will return the explanation based on the existing code of your project.
Find closest files:
File: ../shiva/lib\src\pdf.rs
...
Answer: The `parse` function for PDF files in the provided Rust code is implemented as part of the `Transformer` struct in the `pdf.rs` file. This function is responsible for converting a PDF document into a `Document` object composed of various `Element` types. Here's a detailed breakdown of how it works:
1. **Load the PDF Document**:
- The function takes a reference to a `Bytes` object, which contains the PDF data.
- It uses the `lopdf` library to load the PDF document from memory using `PdfDocument::load_mem`.
2. **Iterate Through Pages**:
- The function retrieves the pages of the PDF using `pdf_document.get_pages()`.
- It iterates over each page to process its contents.
3. **Process Page Contents**:
- For each page, it retrieves the contents using `pdf_document.get_page_contents(page_id)`.
- It iterates over each content object in the page and calls the `parse_object` function to process it.
4. **Parse Individual Objects**:
- The `parse_object` function is responsible for interpreting the contents of each object in the PDF.
- It decodes text using the `PdfDocument::decode_text` method, manages element types like `List`, `Paragraph`, and `Text`, and handles operations associated with text positioning and font changes (e.g., "Tm", "Tf", "Tj", "TJ", "ET").
5. **Text Collection**:
- The function `collect_text` is used to gather and decode text from PDF objects, considering encoding and operand types.
- It adds decoded text to a string and determines when new elements like lists or paragraphs should be started based on the content.
6. **Construct Document Elements**:
- The function constructs `Element` types such as `Text`, `Paragraph`, and `List`, and adds them to a vector of elements.
- These elements are used to build the final `Document` object, representing the structure and content of the PDF.
7. **Return the Document**:
- After processing all pages and objects, the function returns a `Document` instance containing all the parsed elements.
In summary, the `parse` function for PDF files reads the PDF data, iterates through its pages and content objects, decodes text, and constructs a structured `Document` composed of various elements, which can then be used for further processing or transformation.
I would love to see contributions from the community. If you experience bugs, feel free to open an issue. If you would like to implement a new feature or bug fix, please follow the steps: