trishume / syntect

Rust library for syntax highlighting using Sublime Text syntax definitions.
https://docs.rs/syntect
MIT License
1.89k stars 132 forks source link

Remove dependencies from public API #512

Open Enselic opened 9 months ago

Enselic commented 9 months ago

The public API of syntect includes types defined in other crates. This makes it tricky to bump dependencies within a minor syntect release since bumping a dependency can change the syntect public API in incompatible ways.

It would be nice if we for syntect 6.0.0 could go over the public API and remove external types from the public API.

See https://github.com/trishume/syntect/pull/513 for why we want to do this.

How to find inappropriate types in the current public API

Adding

cargo-features = ["public-dependency"]

to Cargo.toml (see https://doc.rust-lang.org/cargo/reference/unstable.html#public-dependency) and building with Rust nightly currently gives these warnings:

output ``` warning: type `bincode::ErrorKind` from private dependency 'bincode' in public interface --> src/dumps.rs:45:1 | 45 | pub fn dump_to_writer(to_dump: &T, output: W) -> Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(exported_private_dependencies)]` on by default warning: type `bincode::ErrorKind` from private dependency 'bincode' in public interface --> src/dumps.rs:66:1 | 66 | pub fn dump_to_file>(o: &T, path: P) -> Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `bincode::ErrorKind` from private dependency 'bincode' in public interface --> src/dumps.rs:73:1 | 73 | pub fn from_reader(input: R) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `bincode::ErrorKind` from private dependency 'bincode' in public interface --> src/dumps.rs:87:1 | 87 | pub fn from_dump_file>(path: P) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `bincode::ErrorKind` from private dependency 'bincode' in public interface --> src/dumps.rs:97:1 | 97 | pub fn dump_to_uncompressed_file>(o: &T, path: P) -> Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `bincode::ErrorKind` from private dependency 'bincode' in public interface --> src/dumps.rs:105:1 | 105 | pub fn from_uncompressed_dump_file>(path: P) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `bincode::ErrorKind` from private dependency 'bincode' in public interface --> src/dumps.rs:114:1 | 114 | pub fn from_uncompressed_data(v: &[u8]) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `serde_json::Value` from private dependency 'serde_json' in public interface --> src/highlighting/settings.rs:10:5 | 10 | fn parse_settings(settings: Settings) -> Result; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `plist::Error` from private dependency 'plist' in public interface --> src/highlighting/settings.rs:19:11 | 19 | Plist(PlistError), | ^^^^^^^^^^ warning: type `plist::Error` from private dependency 'plist' in public interface --> src/highlighting/settings.rs:23:5 | 23 | fn from(error: PlistError) -> SettingsError { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `serde_json::Value` from private dependency 'serde_json' in public interface --> src/highlighting/settings.rs:28:1 | 28 | pub fn read_plist(reader: R) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `serde_json::Value` from private dependency 'serde_json' in public interface --> src/highlighting/theme_load.rs:60:5 | 60 | fn parse_settings(settings: Settings) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `serde_json::Value` from private dependency 'serde_json' in public interface --> src/highlighting/theme_load.rs:90:5 | 90 | fn parse_settings(settings: Settings) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `serde_json::Value` from private dependency 'serde_json' in public interface --> src/highlighting/theme_load.rs:143:5 | 143 | fn parse_settings(settings: Settings) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `serde_json::Value` from private dependency 'serde_json' in public interface --> src/highlighting/theme_load.rs:154:5 | 154 | fn parse_settings(settings: Settings) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `serde_json::Value` from private dependency 'serde_json' in public interface --> src/highlighting/theme_load.rs:186:5 | 186 | fn parse_settings(settings: Settings) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `serde_json::Value` from private dependency 'serde_json' in public interface --> src/highlighting/theme_load.rs:209:5 | 209 | fn parse_settings(json: Settings) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `serde_json::Value` from private dependency 'serde_json' in public interface --> src/highlighting/theme_load.rs:283:5 | 283 | fn parse_settings(settings: Settings) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `ScanError` from private dependency 'yaml_rust' in public interface --> src/parsing/yaml_load.rs:16:25 | 16 | InvalidYaml(#[from] ScanError), | ^^^^^^^^^ warning: type `onig::Region` from private dependency 'onig' in public interface --> src/parsing/regex.rs:144:5 | 144 | pub fn new_region() -> Region { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `onig::Region` from private dependency 'onig' in public interface --> src/parsing/regex.rs:167:9 | 167 | / pub fn search( 168 | | &self, 169 | | text: &str, 170 | | begin: usize, 171 | | end: usize, 172 | | region: Option<&mut Region>, 173 | | ) -> bool { | |_________________^ warning: type `WalkDir` from private dependency 'walkdir' in public interface --> src/utils.rs:9:1 | 9 | pub fn walk_dir>(folder: P) -> WalkDir { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: type `walkdir::Error` from private dependency 'walkdir' in public interface --> src/lib.rs:74:21 | 74 | WalkDir(#[from] walkdir::Error), | ^^^^^^^^^^^^^^ warning: `syntect` (lib) generated 23 warnings ```