feat: expose ruxguitar as a library crate#31
Open
sethbrasile wants to merge 4 commits intoagourlay:masterfrom
Open
feat: expose ruxguitar as a library crate#31sethbrasile wants to merge 4 commits intoagourlay:masterfrom
sethbrasile wants to merge 4 commits intoagourlay:masterfrom
Conversation
Add library entry point and public API for external crate usage: - Add src/lib.rs with public module declarations and re-exports - Add src/error.rs with library-safe RuxError enum (no iced dependency) - Configure Cargo.toml for dual library/binary crate External projects can now depend on ruxguitar to: - Parse Guitar Pro files with parse_gp_data() - Access Song, Track, Measure, Beat, Note types - Generate MIDI events with MidiBuilder - Sequence playback with MidiSequencer Build commands: - `cargo build --lib` - library only - `cargo build --bin ruxguitar` - binary only - `cargo build` - both
- Removed mod parser/audio declarations from main.rs (use library) - Renamed binary RuxError to AppError (keeps IcedError variant) - Added From<LibRuxError> for AppError conversion - Updated config.rs to use ruxguitar::RuxError - Updated UI modules to import from ruxguitar library
- Test that all major types are accessible from library - Test parsing GP5 file using library API - Test MIDI event generation using MidiBuilder - Test error handling for invalid input Verifies COMPAT-03: Library usable as dependency from external project
- Fixed doctest in lib.rs to use MidiBuilder::new() - Updated integration tests to use correct API - Added Default impl for MidiBuilder (clippy warning) - Formatted code with cargo fmt
Owner
|
Thanks for the PR. TBH I have not thought yet about exposing some of the internals as a library crate. I think having more context would help me understand the use case. What are you building exactly? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@agourlay are you open to this? I would like to build an application that uses ruxguitar as its parsing / playback engine. I would like to also contribute some future serialization features for the sake of "save" / "conversion" functionality as my application concept would be stacking a new UI and some editing features on top.
If this is a new direction that deviates from your vision for the project, no pressure, I am happy to maintain a fork with my adjustments! :D
Summary
This PR exposes ruxguitar as a library crate, allowing external Rust projects to use its Guitar Pro parsing and MIDI generation capabilities as a Cargo dependency.
I found myself wanting to use ruxguitar's parsing logic in another project and realized the crate is currently binary-only. Rather than forking, I thought it might be useful to expose the existing functionality as a library that others could also benefit from.
Changes
New files:
src/lib.rs- Library entry point with public module declarations and convenient re-exportssrc/error.rs- Library-safe error type (RuxError) without iced dependencytests/library_usage.rs- Integration tests demonstrating library usageModified files:
Cargo.toml- Added[lib]and[[bin]]sections for dual-target cratesrc/main.rs- Binary now imports from the library; renamed error type toAppErrorto avoid confusion with library'sRuxErrorsrc/config.rs- Updated to use library'sRuxErrorruxguitar::namespaceRationale
Why separate
RuxErrorfromAppError?The existing
RuxErrorinmain.rsincludes anIcedErrorvariant for GUI errors. Since the library shouldn't depend on iced (library consumers may not want the GUI), I created a library-safeRuxErrorinsrc/error.rswith only the core variants (ParsingError, ConfigError, AudioError, IoError). The binary keeps its ownAppErrorthat includesIcedErrorand implementsFrom<RuxError>for ergonomic error handling.What's exposed?
The library re-exports commonly needed types at the crate root for convenience:
parse_gp_data- Main parsing functionSong,Track,Measure,Beat,Note, etc. - Song structure typesMidiBuilder,MidiEvent,MidiEventType,MidiSequencer- MIDI generationFIRST_TICK,QUARTER_TIME- Timing constantsRuxError- Error typeExample usage