
| 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.
bash
ollama pull qwen2.5-coder:7b
ollama pull bge-large # if your need "ask" command functionality for existed project codecargo 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.
bash
rustsn generate function --lang=rust
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)
3. 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
bash
rustsn ask /path/to/your/project --lang=rust
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?
3. 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: 1. Do fork 2. Add comment to the issue that you are going to work on it 3. Create pull request
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Rustsn by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
$ claude mcp add rustsn \
-- python -m otcore.mcp_server <graph>