Skip to content

dciug/rs-enry

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rs-enry

Rust bindings for go-enry

Usage

This package is not published on Cargo yet.

Add this line to your dependency list.

[dependencies]
enry = { git = "https://github.com/go-enry/rs-enry", branch = "master" }

Build

Requirements

To use this library you should have a Go compiler available on your path.

The bindings depend on go-enry v2.6.1 library that is vendored as a submodule in this project.

git clone --recurse-submodules https://github.com/go-enry/rs-enry

# or
git submodule init
git submodule update

Run tests

cargo test

Example

use enry::{get_languages, get_language_by_content, get_language_extensions, get_language};
use std::fs;

fn main() {
    let filename = "src/lib.rs";
    let content = fs::read_to_string(filename).unwrap();

    println!("{:?}", get_language_by_content(filename, content.as_bytes()).unwrap());
    println!("{:?}", get_languages(filename, content.as_bytes()).unwrap());
    println!("{:?}", get_language_extensions("Rust").unwrap());
    println!("{:?}", get_language(filename, content.as_bytes()).unwrap());
}

The program above yields following:

Guess { language: "Rust", safe: true }
["Rust"]
[".rs", ".rs.in"]
"Rust"

You can find more examples on how to use it in tests/test_enry.rs.

About

Rust bindings for enry

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%