Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drewstone/go2rs
https://github.com/drewstone/go2rs
Last synced: 2 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/drewstone/go2rs
- Owner: drewstone
- License: mit
- Created: 2024-11-01T14:12:21.000Z (17 days ago)
- Default Branch: main
- Last Pushed: 2024-11-11T10:19:16.000Z (8 days ago)
- Last Synced: 2024-11-11T10:30:39.773Z (8 days ago)
- Language: Go
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go2rs
[![PkgGoDev](https://pkg.go.dev/badge/drewstone/go2rs)](https://pkg.go.dev/github.com/drewstone/go2rs)## What is go2rs?
- go2rs is a Rust struct generator from Go structs
- Automatically recognizes Go modules in the directory and generates equivalent Rust types
- Handles Go-to-Rust type conversions with appropriate derives and attributes## Installation
```console
$ go get github.com/drewstone/go2rs
```## Usage
```go
// ./example/main.go
package mainimport (
"time"
)type Status string
const (
StatusOK Status = "OK"
StatusFailure Status = "Failure"
)type Param struct {
Status Status
Version int
Action string
CreatedAt time.Time
}
``````console
$ go2rs ./example
```Generates:
```rust
use serde::{Deserialize, Serialize};
use chrono::{DateTime, Utc};#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub enum Status {
OK,
Failure,
}#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct Param {
pub status: Status,
pub version: i32,
pub action: String,
#[serde(with = "chrono::serde::ts_seconds")]
pub created_at: DateTime,
}
```## Features
- Converts Go types to idiomatic Rust types
- Handles common Go patterns like string enums
- Adds appropriate serde derives and attributes
- Supports time.Time conversion to chrono::DateTime
- Maintains field visibility and naming conventions
- Generates documentation from Go comments## TODO
- Handle custom MarshalJSON/UnmarshalJSON implementations## Acknowledgements
This is entirely built using [go2ts](https://github.com/go-generalize/go2ts) by [go-generalize](https://github.com/go-generalize) as a reference and porting over the same concepts to Rust.## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.