Skip to content

Commit 59077d3

Browse files
committed
[Rust] Update repository API following updated Core API's
1 parent fd6f8a2 commit 59077d3

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

rust/src/repository/manager.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,16 @@ use std::ptr::NonNull;
1111

1212
/// Keeps track of all the repositories and keeps the `enabled_plugins.json`
1313
/// file coherent with the plugins that are installed/uninstalled enabled/disabled
14-
pub struct RepositoryManager {
15-
}
14+
pub struct RepositoryManager;
1615

1716
impl RepositoryManager {
18-
pub fn new() -> Self {
19-
Self {}
20-
}
21-
2217
/// Check for updates for all managed [`Repository`] objects
23-
pub fn check_for_updates(&self) -> bool {
18+
pub fn check_for_updates() -> bool {
2419
unsafe { BNRepositoryManagerCheckForUpdates() }
2520
}
2621

2722
/// List of [`Repository`] objects being managed
28-
pub fn repositories(&self) -> Array<Repository> {
23+
pub fn repositories() -> Array<Repository> {
2924
let mut count = 0;
3025
let result =
3126
unsafe { BNRepositoryManagerGetRepositories(&mut count) };
@@ -44,23 +39,23 @@ impl RepositoryManager {
4439
/// * `repository_path` - path to where the repository will be stored on disk locally
4540
///
4641
/// Returns true if the repository was successfully added, false otherwise.
47-
pub fn add_repository(&self, url: &str, repository_path: &Path) -> bool {
42+
pub fn add_repository(url: &str, repository_path: &Path) -> bool {
4843
let url = url.to_cstr();
4944
let repo_path = repository_path.to_cstr();
5045
unsafe {
5146
BNRepositoryManagerAddRepository(url.as_ptr(), repo_path.as_ptr())
5247
}
5348
}
5449

55-
pub fn repository_by_path(&self, path: &Path) -> Option<Repository> {
50+
pub fn repository_by_path(path: &Path) -> Option<Repository> {
5651
let path = path.to_cstr();
5752
let result =
5853
unsafe { BNRepositoryGetRepositoryByPath(path.as_ptr()) };
5954
NonNull::new(result).map(|raw| unsafe { Repository::from_raw(raw) })
6055
}
6156

6257
/// Gets the default [`Repository`]
63-
pub fn default_repository(&self) -> Ref<Repository> {
58+
pub fn default_repository() -> Ref<Repository> {
6459
let result = unsafe { BNRepositoryManagerGetDefaultRepository() };
6560
assert!(!result.is_null());
6661
unsafe { Repository::ref_from_raw(NonNull::new(result).unwrap()) }
@@ -70,7 +65,7 @@ impl RepositoryManager {
7065
impl Debug for RepositoryManager {
7166
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7267
f.debug_struct("RepositoryManager")
73-
.field("repositories", &self.repositories().to_vec())
68+
.field("repositories", &RepositoryManager::repositories().to_vec())
7469
.finish()
7570
}
7671
}

rust/tests/repository.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@ use binaryninja::repository::RepositoryManager;
44
#[test]
55
fn test_list() {
66
let _session = Session::new().expect("Failed to initialize session");
7-
let manager = RepositoryManager::default();
8-
let repositories = manager.repositories();
7+
let repositories = RepositoryManager::repositories();
98
for repository in &repositories {
109
let repo_path = repository.path();
11-
let repository_by_path = manager.repository_by_path(&repo_path).unwrap();
10+
let repository_by_path = RepositoryManager::repository_by_path(&repo_path).unwrap();
1211
assert_eq!(repository.url(), repository_by_path.url());
13-
}
1412

15-
let repository = manager.default_repository();
16-
let _full_path = repository.full_path();
17-
let _path = repository.path();
18-
let _url = repository.url();
19-
let plugins = repository.plugins();
20-
for plugin in &plugins {
21-
let plugin_path = plugin.path();
22-
let plugin_by_path = repository.plugin_by_path(&plugin_path).unwrap();
23-
assert_eq!(plugin.package_url(), plugin_by_path.package_url());
13+
for plugin in &repository.plugins() {
14+
let plugin_path = plugin.path();
15+
let plugin_by_path = repository.plugin_by_path(&plugin_path).unwrap();
16+
assert_eq!(plugin.package_url(), plugin_by_path.package_url());
17+
}
2418
}
2519
}

0 commit comments

Comments
 (0)