| Crates.io | cocoanut |
| lib.rs | cocoanut |
| version | 0.1.1 |
| created_at | 2025-10-24 17:18:11.656194+00 |
| updated_at | 2025-10-25 10:22:17.355591+00 |
| description | A Rust wrapper for Cocoa to develop macOS-specific GUI applications |
| homepage | |
| repository | https://github.com/yingkitw/cocoanut |
| max_upload_size | |
| id | 1898885 |
| size | 1,094,032 |
A Rust wrapper for Cocoa to develop macOS-specific GUI applications with idiomatic, simple APIs.
Raw objc and cocoa crates require:
Cocoanut provides:
let button = Button::new("Click")?;
button.set_title("Updated")?;
button.set_size(100.0, 50.0)?;
button.set_enabled(true)?;
window.add_subview(button, 10.0, 10.0, 100.0, 50.0)?;
let button = Button::builder()
.title("Updated")
.size(100.0, 50.0)
.enabled(true)
.build()?;
let vstack = VStack::new()
.spacing(Spacing::standard())
.alignment(Alignment::Center);
| Crate | Level | Safety | Learning Curve | Performance | Best For |
|---|---|---|---|---|---|
objc |
Very Low | Low | High | Highest | System programming |
objc2 |
Low | Medium | High | High | Performance-critical |
cocoa |
Medium | Medium | Medium | High | Legacy code |
cacao |
High | High | Low | Medium | Cross-platform apps |
cocoanut |
Low-Medium | High | Low | High | Learning & prototyping |
Recommendation: Start with Cocoanut to learn macOS GUI development in Rust!
cargo add cocoanut
use cocoanut::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a window
let window = Window::builder()
.title("My App")
.size(600.0, 400.0)
.center()
.build()?;
// Run the app - components display automatically!
app("MyApp")
.with_window(window)
.run()?;
Ok(())
}
That's it! The app will display a window with Button, Label, and TextField components automatically.
Run it:
cargo run
Run examples to see Cocoanut in action:
# Minimal app with components
cargo run --example minimal_app
# Basic window
cargo run --example basic_window
# Menu application
cargo run --example menu_app
# Comprehensive component demo
cargo run --example comprehensive_app
# Layout & Containers Demo - Educational overview
cargo run --example layout_and_containers_demo
# Layout Patterns Demo - Real-world patterns
cargo run --example layout_patterns
# Containers with Borders Demo - Visual container demonstration
cargo run --example containers_with_borders
All examples display real macOS GUI windows with interactive components. Press Cmd+Q to quit.
Layout & Containers Demos:
See docs/EXAMPLES_AND_TESTS.md for all examples.
cargo build
cargo run --example basic_window
cargo run --example menu_app
cargo test
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Complete documentation is available in DOCUMENTATION.md. Key guides: