Cornell Notes Library
A Rust library for reading, writing, and validating Cornell Notes in standardized JSON format, implementing the Cornell Notes Data Schema RFC.
Features
- Type-safe data structures for Cornell Notes components
- Comprehensive validation of all schema requirements
- JSON serialization/deserialization with serde
- Markdown export for easy reading and sharing
- File I/O operations for reading and writing notes
- Support for structured content (Markdown, HTML, plain text)
- Cue-to-note linking for relational study tools
- UUID-based identification for distributed creation
- ISO 8601 datetime handling with chrono
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use ;
// Create a new Cornell Note
let mut note = new;
// Create a section
let mut section = new;
// Add a cue (left column)
let cue = new;
section.add_cue;
// Add a note (right column)
let note_entry = new;
section.add_note;
// Add section to note
note.add_section;
// Add summary
note.update_summary;
// Validate the note
note.validate?;
// Save to file
write_to_file?;
// Load from file
let loaded = read_from_file?;
// Export to Markdown
let markdown = to_markdown;
println!;
// Or save directly to file
write_to_markdown_file?;
Markdown Export
The library supports exporting Cornell Notes to Markdown format, following the RFC specification:
use ;
let note = new;
// ... build your note ...
// Convert to Markdown string
let markdown = to_markdown;
// Or write directly to file
write_to_markdown_file?;
The markdown format organizes content hierarchically:
**Subject:** [Subject]
**Topic:** [Topic]
**Author:** [Author]
**Tags:** [tag1, tag2, ...]
- -
[Notes content]
-
[Notes content]
[Summary content]
This format is ideal for:
- Reading: Easy to read in any markdown viewer
- Sharing: Works on GitHub, GitLab, and other platforms
- Editing: Simple text format for quick edits
- Printing: Convert to PDF via markdown tools
Core Types
CornellNote
The main document structure containing:
version: Schema version (e.g., "1.0")metadata: Document metadata (title, author, timestamps, etc.)sections: Array of note sectionssummary: Summary section
Section
A logical grouping of cues and notes:
id: UUID identifiercues: Array of cue entries (left column)notes: Array of note entries (right column)position: Order within the document
Cue
A prompt or keyword in the left column:
id: UUID identifiercontent: String or structured contenttype: CueType (Text, Question, Keyword, Custom)position: Order within sectioncreated,modified: Timestamps
Note
A detailed note in the right column:
id: UUID identifiercontent: String or structured contenttype: NoteType (Text, List, Code, Image, Link, Custom)position: Order within sectioncue_links: Optional links to related cuescreated,modified: Timestamps
Content
Flexible content representation:
// Simple string content
Simple
// Structured content with formatting
Structured
Validation
The library provides comprehensive validation:
use CornellNote;
let note = new;
match note.validate
Validation checks include:
- Version format matches
^[0-9]+\.[0-9]+$ - Title is non-empty
- At least one section exists
- No duplicate IDs or positions
- Cue links reference existing cues
- Modified dates are not before created dates
JSON Format
The library produces JSON conforming to the Cornell Notes schema:
Examples
Run the basic usage example:
This will create an example note and save it to example_note.json.
API Reference
Top-level Functions
JSON Operations
from_json(json: &str) -> Result<CornellNote>- Parse and validate JSONfrom_json_unchecked(json: &str) -> Result<CornellNote>- Parse without validationto_json(note: &CornellNote) -> Result<String>- Serialize to compact JSONto_json_pretty(note: &CornellNote) -> Result<String>- Serialize to formatted JSONread_from_file(path: &str) -> Result<CornellNote>- Read and validate from filewrite_to_file(note: &CornellNote, path: &str) -> Result<()>- Write to file
Markdown Export
to_markdown(note: &CornellNote) -> String- Export to Markdown stringwrite_to_markdown_file(note: &CornellNote, path: &str) -> Result<()>- Write to Markdown file
Error Handling
All operations return cornell_notes::Result<T> which uses the CornellNoteError enum:
JsonError- JSON parsing errorsValidationError- Schema validation failuresIoError- File I/O errorsInvalidVersion- Version format errorsInvalidUuid- UUID format errorsInvalidDatetime- Datetime format errors
Testing
Run the test suite:
The library includes comprehensive tests for:
- Structure creation and manipulation
- Validation logic
- JSON serialization/deserialization
- File I/O operations
- Error conditions
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.