Skip to content

Commit

Permalink
feat: initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dpastoor committed May 26, 2024
1 parent 92fafcf commit afb70fc
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 20 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(hello_world)
export(os_info)
useDynLib(osinfo, .registration = TRUE)
12 changes: 9 additions & 3 deletions R/extendr-wrappers.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Generated by extendr: Do not edit by hand

# nolint start

#
# This file was created with the following call:
# .Call("wrap__make_osinfo_wrappers", use_symbols = TRUE, package_name = "osinfo")

#' @docType package
#' @usage NULL
#' @useDynLib osinfo, .registration = TRUE
NULL

#' Return string `"Hello world!"` to R.
#' @export
hello_world <- function() .Call(wrap__hello_world)
#' get os information
os_info_impl <- function() .Call(wrap__os_info_impl)


# nolint end
5 changes: 5 additions & 0 deletions R/os-info.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#' get os info
#' @export
os_info <- function() {
os_info_impl()
}
11 changes: 0 additions & 11 deletions man/hello_world.Rd

This file was deleted.

11 changes: 11 additions & 0 deletions man/os_info.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/os_info_impl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ name = 'osinfo'

[dependencies]
extendr-api = '*'
os_info = { version = "3", default-features = false }
21 changes: 16 additions & 5 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
use extendr_api::prelude::*;

/// Return string `"Hello world!"` to R.
/// @export
#[derive(Debug, PartialEq, IntoDataFrameRow)]
struct OsInfo {
version: String,
os_type: String,
architecture: Option<String>,
}
/// get os information
#[extendr]
fn hello_world() -> &'static str {
"Hello world!"
fn os_info_impl() -> List {
let info = os_info::get();
list!(
version = info.version().to_string(),
os_type = info.os_type().to_string(),
architecture = info.architecture(),
codename = info.codename()
)
}

// Macro to generate exports.
// This ensures exported functions are registered with R.
// See corresponding C code in `entrypoint.c`.
extendr_module! {
mod osinfo;
fn hello_world;
fn os_info_impl;
}

0 comments on commit afb70fc

Please sign in to comment.