Skip to content

Is there a way to use references in callbacks? #455

@MrKekovichPersonal

Description

@MrKekovichPersonal

When I am trying to create callback with pointers, flapigen cannot convert &Type to java:
rust code:

#[generate_interface]
pub trait GetScoreCallback {
    fn get_score(&mut self, network: &NeuralNetwork) -> f64;
}

generated interface:

foreign_callback!(
	callback GetScoreCallback {
		self_type GetScoreCallback;
		getScore = GetScoreCallback::get_score(& mut self , network : & NeuralNetwork)->f64;
	}
);

error:

  parsing of java-api-for-rust: src/generated/java_glue.rs.in failed
  error: Do not know conversion from such rust type '& NeuralNetwork' to Java type
  		getScore = GetScoreCallback::get_score(& mut self , network : & NeuralNetwork)->f64;

However, when I am using references wtih class method - it works:

pub struct Something;
impl Something {
    #[generate_interface]
    pub fn something(net: &NeuralNetwork) {}
}
foreign_class!(
	class Something {
		fn Something::something(net : & NeuralNetwork); alias something;
	}
);

Copying network is a compute-intense process.
Is there any way to solve this problem without copying?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Java/JNICase specific only for Java/JNI interface generationquestion

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions